Skip to content
This repository has been archived by the owner on Sep 4, 2019. It is now read-only.

Commit

Permalink
add some comments to main.cpp to help to understand how the interpret…
Browse files Browse the repository at this point in the history
…er must be used
  • Loading branch information
jesustorresdev committed Aug 6, 2011
1 parent 9517a27 commit 087b209
Showing 1 changed file with 37 additions and 8 deletions.
45 changes: 37 additions & 8 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,31 +29,60 @@ const char INTRO_TEXT[] = "\x1b[2J\x1b[H"

const char PROMPT_TEXT[] = "$ ";

//
// Function to be invoked by the interpreter when the user inputs the
// 'exit' command.
//
// See include/cli/shell_parser.hpp for
// cli::parser::shellparser::CommandDetails definition.
//

bool exitCommandCallback(const std::string& command,
cli::parser::shellparser::CommandDetails const& details)
{
return true;
}

//
// Function to be invoked by the interpreter when the user inputs any
// other command.
//
// See include/cli/shell_parser.hpp for
// cli::parser::shellparser::CommandDetails definition.
//

bool defaultCommandCallback(const std::string& command,
const cli::parser::shellparser::CommandDetails& details)
cli::parser::shellparser::CommandDetails const& details)
{
std::cout << command << ": ";
std::cout << details << std::endl;
return false;
}

bool exitCommandCallback(const std::string& command,
const cli::parser::shellparser::CommandDetails& details)
{
return true;
}
//
// Main function
//

int main(int argc, char** argv)
{
// Create the interpreter object with the ShellParser parser
cli::CommandLineInterpreter<cli::parser::ShellParser> interpreter;

// Set the intro and prompt texts
interpreter.setIntroText(INTRO_TEXT);
interpreter.setPromptText(PROMPT_TEXT);

interpreter.setCallback<cli::callback::DoCommandCallback>(
&defaultCommandCallback);
// Set the callback function that will be invoked when the user inputs
// the 'exit' command
interpreter.setCallback<cli::callback::DoCommandCallback>(
&exitCommandCallback, "exit");

// Set the callback function that will be invoked when the user inputs
// any other command
interpreter.setCallback<cli::callback::DoCommandCallback>(
&defaultCommandCallback);

// Run the interpreter
interpreter.loop();

return 0;
Expand Down

0 comments on commit 087b209

Please sign in to comment.