Parsing the command line in C++
Argstream is a "library" for parsing the command line arguments in a C++ program. It is released under the GPL license. Here is a list of functionalities offered for the parsing of command line arguments :
- Short (-c) and long ( --color) names for switches, short names being optional (there is only a limited number of character so you might need to define switches without short names);
- Case sensitive switches (-c is different of -C);
-
Three types of arguments :
- option: associated to bool variables that are set to true if the switch is present on the command line or false otherwise (ex: ls -l);
- parameter: associated to a variable of any type whose value is set to the argument following on command line (ex: dvips -o foo.ps);
- values: sequence of specifiable length (eventually variable) of arguments on the command line (ex: gzip foo.txt bar.txt foobar.eps);
- Possibility for optional parameter with default value;
- Possibility for parameter values starting with - through the use of the special -- switch;
- Automatic handling of help and errors;
- Possibility for complex parsing such as switches available only if a condition is met by previously parsed switches;
- Groupable options (ex: tar -xvf foo.tar as a shorthand for tar -x -v -f foo.tar);
- Possibility to extend to user defined types very simply;
- Simple and concise interface, with just a header file to include (no library to link with);
Here is below an example of use that should match almost all your needs :