.\" This is a wxWidgets manpage page generated from the XML docs .TH wxCmdLineParser 3wx 2005-02-15 "wxWidgets" "wxWidgets class documentation" .SH NAME wxCmdLineParser \- Command line parser class .SH DESCRIPTION wxCmdLineParser is a class for parsing the command line. It has the following features: distinguishes options, switches and parameters; allows option grouping allows both short and long options automatically generates the usage message from the command line description does type checks on the options values (number, date, \ldots). To use it you should follow these steps: construct an object of this class giving it the command line to parse and optionally its description or use AddXXX() functions later call Parse() use Found() to retrieve the results In the documentation below the following terminology is used: switch This is a boolean option which can be given or not, but which doesn't have any value. We use the word switch to distinguish such boolean options from more generic options like those described below. For example, -v might be a switch meaning "enable verbose mode". option Option for us here is something which comes with a value 0 unlike a switch. For example, -o:filename might be an option which allows to specify the name of the output file. parameter This is a required program argument. .SH "PARENTS" .SH "INCLUDE FILES" wx/cmdline.h .SH MEMBERS .SS wxCmdLineParser () Default constructor. You must use SetCmdLine later. .SS wxCmdLineParser (int argcchar** argv) .SS wxCmdLineParser (int argcwchar_t** argv) Constructor specifies the command line to parse. This is the traditional (Unix) command line format. The parameters argc and argv have the same meaning as for main() function. The second overloaded constructor is only available in Unicode build. The first one is available in both ANSI and Unicode modes because under some platforms the command line arguments are passed as ASCII strings even to Unicode programs. .SS wxCmdLineParser (const wxString& cmdline) Constructor specifies the command line to parse in Windows format. The parameter cmdline has the same meaning as the corresponding parameter of WinMain() . .SS wxCmdLineParser (const wxCmdLineEntryDesc* desc) Same as wxCmdLineParser , but also specifies the command line description . .SS wxCmdLineParser (const wxCmdLineEntryDesc* descint argcchar** argv) Same as wxCmdLineParser , but also specifies the command line description . .SS wxCmdLineParser (const wxCmdLineEntryDesc* descconst wxString& cmdline) Same as wxCmdLineParser , but also specifies the command line description . .SS static wxArrayString ConvertStringToArgs (const wxChar *cmdline) Breaks down the string containing the full command line in words. The words are separated by whitespace. The quotes can be used in the input string to quote the white space and the back slashes can be used to quote the quotes. .SS void SetCmdLine (int argcchar** argv) .SS void SetCmdLine (int argcwchar_t** argv) Set command line to parse after using one of the constructors which don't do it. The second overload of this function is only available in Unicode build. .SS void SetCmdLine (const wxString& cmdline) Set command line to parse after using one of the constructors which don't do it. .SS ~wxCmdLineParser () Frees resources allocated by the object. NB: destructor is not virtual, don't use this class polymorphically. .SS void SetSwitchChars (const wxString& switchChars) switchChars contains all characters with which an option or switch may start. Default is "-" for Unix, "-/" for Windows. .SS void EnableLongOptions (bool enable = true) Enable or disable support for the long options. As long options are not (yet) POSIX-compliant, this option allows to disable them. .SS void DisableLongOptions () Identical to EnableLongOptions(false) . .SS bool AreLongOptionsEnabled () Returns true if long options are enabled, otherwise false. .SS void SetLogo (const wxString& logo) logo is some extra text which will be shown by Usage method. .SS void SetDesc (const wxCmdLineEntryDesc* desc) Construct the command line description Take the command line description from the wxCMD_LINE_NONE terminated table. Example of usage: static const wxCmdLineEntryDesc cmdLineDesc[] = { { wxCMD_LINE_SWITCH, "v", "verbose", "be verbose" }, { wxCMD_LINE_SWITCH, "q", "quiet", "be quiet" }, { wxCMD_LINE_OPTION, "o", "output", "output file" }, { wxCMD_LINE_OPTION, "i", "input", "input dir" }, { wxCMD_LINE_OPTION, "s", "size", "output block size", wxCMD_LINE_VAL_NUMBER }, { wxCMD_LINE_OPTION, "d", "date", "output file date", wxCMD_LINE_VAL_DATE }, { wxCMD_LINE_PARAM, NULL, NULL, "input file", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_MULTIPLE }, { wxCMD_LINE_NONE } }; wxCmdLineParser parser; parser.SetDesc(cmdLineDesc); .SS void AddSwitch (const wxString& nameconst wxString& lng = wxEmptyStringconst wxString& desc = wxEmptyStringint flags = 0) Add a switch name with an optional long name lng (no long name if it is empty, which is default), description desc and flags flags to the command line description. .SS void AddOption (const wxString& nameconst wxString& lng = wxEmptyStringconst wxString& desc = wxEmptyStringwxCmdLineParamType type = wxCMD_LINE_VAL_STRINGint flags = 0) Add an option name with an optional long name lng (no long name if it is empty, which is default) taking a value of the given type (string by default) to the command line description. .SS void AddParam (const wxString& desc = wxEmptyStringwxCmdLineParamType type = wxCMD_LINE_VAL_STRINGint flags = 0) Add a parameter of the given type to the command line description. .SS int Parse (bool giveUsage = true) Parse the command line, return 0 if ok, -1 if "-h" or "--help" option was encountered and the help message was given or a positive value if a syntax error occurred. .SS void Usage () Give the standard usage message describing all program options. It will use the options and parameters descriptions specified earlier, so the resulting message will not be helpful to the user unless the descriptions were indeed specified. .SS bool Found (const wxString& name) Returns true if the given switch was found, false otherwise. .SS bool Found (const wxString& namewxString* value) Returns true if an option taking a string value was found and stores the value in the provided pointer (which should not be NULL). .SS bool Found (const wxString& namelong* value) Returns true if an option taking an integer value was found and stores the value in the provided pointer (which should not be NULL). .SS bool Found (const wxString& namewxDateTime* value) Returns true if an option taking a date value was found and stores the value in the provided pointer (which should not be NULL). .SS size_t GetParamCount () Returns the number of parameters found. This function makes sense mostly if you had used wxCMD_LINE_PARAM_MULTIPLE flag. .SS wxString GetParam (size_t n = 0u) Returns the value of Nth parameter (as string only for now). .SH "SEE ALSO" wxApp::argc and wxApp::argv console sample .SH "AUTHORS" Documentation content by Julian Smart, Robert Roebling, Vadim Zeitlin, Robin Dunn, et al Conversion to manpage format by Arnout Engelen (http://bzzt.net), bugreports welcome.