Skip to content
Snippets Groups Projects
Commit 8049e4e0 authored by Florian Pose's avatar Florian Pose
Browse files

Output requested help to stdout, help on invalid usage to stderr.

parent 5da73c9d
No related branches found
No related tags found
No related merge requests found
...@@ -41,7 +41,7 @@ struct Command { ...@@ -41,7 +41,7 @@ struct Command {
const char *briefDesc; const char *briefDesc;
int execute(void) const; int execute(void) const;
void displayHelp(void) const; string getHelpString(void) const;
}; };
/*****************************************************************************/ /*****************************************************************************/
...@@ -251,7 +251,7 @@ int Command::execute() const ...@@ -251,7 +251,7 @@ int Command::execute() const
func(); func();
} catch (InvalidUsageException &e) { } catch (InvalidUsageException &e) {
cerr << e.what() << endl << endl; cerr << e.what() << endl << endl;
displayHelp(); cerr << getHelpString();
return 1; return 1;
} catch (CommandException &e) { } catch (CommandException &e) {
cerr << e.what() << endl; cerr << e.what() << endl;
...@@ -266,9 +266,11 @@ int Command::execute() const ...@@ -266,9 +266,11 @@ int Command::execute() const
/****************************************************************************/ /****************************************************************************/
void Command::displayHelp() const string Command::getHelpString() const
{ {
cerr << binaryBaseName << " " << commandName << " " << helpString; stringstream help;
help << binaryBaseName << " " << commandName << " " << helpString;
return help.str();
} }
/****************************************************************************/ /****************************************************************************/
...@@ -342,7 +344,7 @@ int main(int argc, char **argv) ...@@ -342,7 +344,7 @@ int main(int argc, char **argv)
masterDev.setIndex(masterIndex); masterDev.setIndex(masterIndex);
retval = cmd->execute(); retval = cmd->execute();
} else { } else {
cmd->displayHelp(); cout << cmd->getHelpString();
} }
} else { } else {
cerr << "Ambiguous command abbreviation! Matching:" << endl; cerr << "Ambiguous command abbreviation! Matching:" << endl;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment