Output requested help to stdout, help on invalid usage to stderr.
authorFlorian Pose <fp@igh-essen.com>
Thu, 24 Jul 2008 07:40:45 +0000
changeset 1139 074caa25365e
parent 1138 4149af40c0e2
child 1140 cc779f7d2496
Output requested help to stdout, help on invalid usage to stderr.
tool/main.cpp
--- a/tool/main.cpp	Wed Jul 23 16:18:48 2008 +0000
+++ b/tool/main.cpp	Thu Jul 24 07:40:45 2008 +0000
@@ -41,7 +41,7 @@
     const char *briefDesc;
 
     int execute(void) const;
-    void displayHelp(void) const;
+    string getHelpString(void) const;
 };
 
 /*****************************************************************************/
@@ -251,7 +251,7 @@
         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 @@
 
 /****************************************************************************/
 
-void Command::displayHelp() const
-{
-    cerr << binaryBaseName << " " << commandName << " " << helpString;
+string Command::getHelpString() const
+{
+    stringstream help;
+    help << binaryBaseName << " " << commandName << " " << helpString;
+    return help.str();
 }
 
 /****************************************************************************/
@@ -342,7 +344,7 @@
                 masterDev.setIndex(masterIndex);
                 retval = cmd->execute();
             } else {
-                cmd->displayHelp();
+                cout << cmd->getHelpString();
             }
         } else {
             cerr << "Ambiguous command abbreviation! Matching:" << endl;