From 6729e56a6c887fbeda83c163b3f002cc4b1498d4 Mon Sep 17 00:00:00 2001 From: Florian Pose Date: Thu, 24 Jul 2008 07:40:45 +0000 Subject: [PATCH] Output requested help to stdout, help on invalid usage to stderr. --- tool/main.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/tool/main.cpp b/tool/main.cpp index 1b5e297d..a07d83b1 100644 --- a/tool/main.cpp +++ b/tool/main.cpp @@ -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;