]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/cmdline.cpp
1. applied (heavily modified) patch for reading CUR files by Chris
[wxWidgets.git] / src / common / cmdline.cpp
index efb4a3e9664c50ead898e5fdd547c3093c6c659d..2b550d15ec8ff82dac3bca6045f137aa16a07f90 100644 (file)
@@ -109,7 +109,9 @@ struct wxCmdLineOption
 
 public:
     wxCmdLineEntryType kind;
-    wxString shortName, longName, description;
+    wxString shortName,
+             longName,
+             description;
     wxCmdLineParamType type;
     int flags;
 
@@ -476,7 +478,7 @@ void wxCmdLineParser::Reset()
 // the real work is done here
 // ----------------------------------------------------------------------------
 
-int wxCmdLineParser::Parse()
+int wxCmdLineParser::Parse(bool showUsage)
 {
     bool maybeOption = TRUE;    // can the following arg be an option?
     bool ok = TRUE;             // TRUE until an error is detected
@@ -803,7 +805,7 @@ int wxCmdLineParser::Parse()
         }
     }
 
-    if ( !ok )
+    if ( !ok && showUsage )
     {
         Usage();
     }
@@ -849,13 +851,30 @@ void wxCmdLineParser::Usage()
             brief << _T('[');
         }
 
-        brief << chSwitch << opt.shortName;
+        if ( !opt.shortName.empty() )
+        {
+            brief << chSwitch << opt.shortName;
+        }
+        else if ( !opt.longName.empty() )
+        {
+            brief << _T("--") << opt.longName;
+        }
+        else
+        {
+            wxFAIL_MSG( _T("option without neither short nor long name?") );
+        }
 
         wxString option;
-        option << _T("  ") << chSwitch << opt.shortName;
-        if ( !!opt.longName )
+
+        if ( !opt.shortName.empty() )
+        {
+            option << _T("  ") << chSwitch << opt.shortName;
+        }
+
+        if ( !opt.longName.empty() )
         {
-            option << _T("  --") << opt.longName;
+            option << (option.empty() ? _T("  ") : _T(", "))
+                   << _T("--") << opt.longName;
         }
 
         if ( opt.kind != wxCMD_LINE_SWITCH )
@@ -904,7 +923,13 @@ void wxCmdLineParser::Usage()
         wxLogMessage(m_data->m_logo);
     }
 
+    // in console mode we want to show the brief usage message first, then the
+    // detailed one but in GUI build we give the details first and then the
+    // summary - like this, the brief message appears in the wxLogGui dialog,
+    // as expected
+#if !wxUSE_GUI
     wxLogMessage(brief);
+#endif // !wxUSE_GUI
 
     // now construct the detailed help message
     size_t len, lenMax = 0;
@@ -927,6 +952,11 @@ void wxCmdLineParser::Usage()
     }
 
     wxLogMessage(detailed);
+
+    // do it now if not done above
+#if wxUSE_GUI
+    wxLogMessage(brief);
+#endif // wxUSE_GUI
 }
 
 // ----------------------------------------------------------------------------