]> git.mxchange.org Git - flightgear.git/commitdiff
Erik Hofman:
authorcurt <curt>
Sun, 25 Aug 2002 22:38:20 +0000 (22:38 +0000)
committercurt <curt>
Sun, 25 Aug 2002 22:38:20 +0000 (22:38 +0000)
I've modified the code to display a brief help message instead of the
whole bunch of options. To get the complete message -v or --verbose has
to be added to the command line.

src/Main/options.cxx
src/Main/options.hxx

index 5f37bfcc8f6165ec3b7a6dac4525d057d1c27ec7..5d30b18365494b2bf7ace698dad779debf5c4ebe 100644 (file)
@@ -68,7 +68,8 @@ enum
 {
     FG_OPTIONS_OK = 0,
     FG_OPTIONS_HELP = 1,
-    FG_OPTIONS_ERROR = 2
+    FG_OPTIONS_ERROR = 2,
+    FG_OPTIONS_VERBOSE_HELP = 3
 };
 
 static double
@@ -594,6 +595,9 @@ parse_option (const string& arg)
     if ( (arg == "--help") || (arg == "-h") ) {
        // help/usage request
        return(FG_OPTIONS_HELP);
+    } else if ( (arg == "--verbose") || (arg == "-v") ) {
+        // verbose help/usage request
+        return(FG_OPTIONS_VERBOSE_HELP);
     } else if ( arg == "--disable-game-mode") {
        fgSetBool("/sim/startup/game-mode", false);
     } else if ( arg == "--enable-game-mode" ) {
@@ -1061,6 +1065,8 @@ void
 fgParseArgs (int argc, char **argv)
 {
     bool in_options = true;
+    bool verbose = false;
+    bool help = false;
 
     SG_LOG(SG_GENERAL, SG_INFO, "Processing command line arguments");
 
@@ -1072,11 +1078,11 @@ fgParseArgs (int argc, char **argv)
            in_options = false;
          } else {
            int result = parse_option(arg);
-           if ( (result == FG_OPTIONS_HELP) ||
-                (result == FG_OPTIONS_ERROR) ) {
-             fgUsage();
-             exit(-1);
-           }
+           if ((result == FG_OPTIONS_HELP) || (result == FG_OPTIONS_ERROR))
+              help = true;
+
+            else if (result == FG_OPTIONS_VERBOSE_HELP)
+              verbose = true;
          }
        } else {
          in_options = false;
@@ -1086,6 +1092,11 @@ fgParseArgs (int argc, char **argv)
        }
     }
 
+    if (help) {
+       fgUsage(verbose);
+       exit(0);
+    }
+
     SG_LOG(SG_GENERAL, SG_INFO, "Finished command line arguments");
 }
 
@@ -1135,7 +1146,7 @@ fgParseOptions (const string& path) {
 
 // Print usage message
 void 
-fgUsage ()
+fgUsage (bool verbose)
 {
     SGPropertyNode options_root;
     SGPath opath( globals->get_fg_root() );
@@ -1168,11 +1179,7 @@ fgUsage ()
 
     vector<SGPropertyNode_ptr>section = options->getChildren("section");
     for (unsigned int j = 0; j < section.size(); j++) {
-
-        SGPropertyNode *name = section[j]->getNode("name");
-        if (name) {
-            cout << endl << name->getStringValue() << ":" << endl;
-        }
+        string msg = "";
 
         vector<SGPropertyNode_ptr>option = section[j]->getChildren("option");
         for (unsigned int k = 0; k < option.size(); k++) {
@@ -1181,8 +1188,9 @@ fgUsage ()
             SGPropertyNode *short_name = option[k]->getNode("short");
             SGPropertyNode *key = option[k]->getNode("key");
             SGPropertyNode *arg = option[k]->getNode("arg");
+            bool brief = option[k]->getNode("brief");
 
-            if (name) {
+            if ((brief || verbose) && name) {
                 string tmp = name->getStringValue();
 
                 if (key){
@@ -1204,8 +1212,8 @@ fgUsage ()
                 } else {
                     snprintf(cstr, 96, "\n   --%s\n%32c", tmp.c_str(), ' ');
                 }
-                string msg = cstr;
 
+                msg += cstr;
                 SGPropertyNode *desc = option[k]->getNode("description");
                 if (desc) {
                     msg += desc->getStringValue();
@@ -1218,9 +1226,21 @@ fgUsage ()
                                  desc->getStringValue());
                         msg += cstr;
                     }
+                    msg += '\n';
                 }
-                cout << msg << endl;
             }
         }
+
+        SGPropertyNode *name = section[j]->getNode("name");
+        if (!msg.empty() && name) {
+           cout << endl << name->getStringValue() << ":" << endl;
+           cout << msg;
+           msg.erase();
+        }
+    }
+
+    if ( !verbose ) {
+        cout << endl;
+        cout << "For a complete list of options use --help --verbose" << endl;
     }
 }
index b9e0aeb6024f9193d37d0fda730cecd215a0d479..7d6866dde12062bb84e0f2aeb58c1903084a28a9 100644 (file)
@@ -34,6 +34,6 @@ extern string fgScanForRoot (int argc, char ** argv);
 extern string fgScanForRoot (const string &file_path);
 extern void fgParseArgs (int argc, char ** argv);
 extern void fgParseOptions (const string &file_path);
-extern void fgUsage ();
+extern void fgUsage (bool verbose = false);
 
 #endif /* _OPTIONS_HXX */