Home | All Classes | Grouped Classes | Index | Search
Helper class to parse command line arguments More...
Derived from:
none
Derived by:
none
Group: Core (System)
#include <ClanLib/core.h>
Construction:
Attributes:
Return the key of the current option | |
Return the argument to the current option |
Operations:
Change the indention used for the help message, default is 18 | |
Add a usage line to the help output, usage is for example "[OPTIONS]... FILE", the program name will get appended automatically | |
Adds extra documentation to the help output, should only be used at the beginning or at the end, to | |
Starts a new group of options, the grouptopic gets printed above the group of options in the print_help() output | |
Adds a option to the parser | |
Parse the options arcording to the options added with add_option(), result of the parsing is accessible via next() and get_key()/get_argument() | |
Print the help output, normaly done via a --help option | |
Goto the next option |
Detailed description:
!group=Core/System! !header=core.h!The CL_CommandLine class helps to parse command line arguments, namely the argc/argv pair that you get from main(). CL_CommandLine mimics getopt_long() behaviour as closely as possible, while providing a cleaner interface and a few additional features, like automatic generation of '--help' output. CL_CommandLine can parse long arguments in the following styles:
program --file FILENAME
program --file=FILENAME
Short arguments are handled like this:
program -f FILENAME
Concatenating short arguments is also supported, so that:
program -f -a -b FILENAME
is equivalent to:
program -fab FILENAME
Non-option arguments (aka rest arguments) are supported as well:
program SOMEFILE SOMEOTHERFILE ...
To avoid ambiguity when a filename starts with '-' CL_CommandLine stops parsing arguments after the first encounter of a '--', so in
program -f -b -- -f -b
In the above example the first '-f -b' options are treated as normal while the ones after the '--' are treated as rest arguments (aka filenames in most programs).