Command line parsing

Kenneth Porter shiva.blacklist at sewingwitch.com
Sun Mar 11 07:45:47 PDT 2007


vadim at wxwindows.org (Vadim Zeitlin) wrote in
news:856YZB.A.YwQ.t9-8FB at brage.sunsite.dk: 

>  If YourApp::OnInit() calls wxApp::OnInit() parsing is done inside
>  wxApp 
> itself and uses OnInitCmdLine() and OnCmdLine{Help/Parsed/Error}()
> virtual methods to allow you to customize it.

Thanks! I'd read through all the wx sources and headers for the 
application and cmdline classes and figured out how the overrides work 
and when they're called. I came up with the following simple override for 
my needs. The one thing I found confusing was that SetDesc seems to 
append to the existing options, not replace them. The name would suggest 
replacement. (There are some default command line options installed in 
the application base classes.)

void MyApp::OnInitCmdLine(wxCmdLineParser& parser)
{
   wxApp::OnInitCmdLine(parser);

   static const wxCmdLineEntryDesc cmdLineDesc[] =
   {
      {
         wxCMD_LINE_PARAM,
         wxEmptyString,
         wxEmptyString,
         gettext_noop("select a configuration"),
         wxCMD_LINE_VAL_STRING,
         wxCMD_LINE_PARAM_OPTIONAL
      },

      // terminator
      {
         wxCMD_LINE_NONE,
         wxEmptyString,
         wxEmptyString,
         wxEmptyString,
         wxCMD_LINE_VAL_NONE,
         0x0
      }
   };

   parser.SetDesc(cmdLineDesc);

}






More information about the wx-users mailing list