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

This commit is contained in:
Florian Pose 2008-07-24 07:40:45 +00:00
parent 1974daf339
commit 6729e56a6c
1 changed files with 7 additions and 5 deletions

View File

@ -41,7 +41,7 @@ struct Command {
const char *briefDesc;
int execute(void) const;
void displayHelp(void) const;
string getHelpString(void) const;
};
/*****************************************************************************/
@ -251,7 +251,7 @@ int Command::execute() const
func();
} catch (InvalidUsageException &e) {
cerr << e.what() << endl << endl;
displayHelp();
cerr << getHelpString();
return 1;
} catch (CommandException &e) {
cerr << e.what() << endl;
@ -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)
masterDev.setIndex(masterIndex);
retval = cmd->execute();
} else {
cmd->displayHelp();
cout << cmd->getHelpString();
}
} else {
cerr << "Ambiguous command abbreviation! Matching:" << endl;