You surely have some experience with command line programs. Such programs usually allow the user to set various arguments to alter programs behavior. The format of the arguments slightly differs from application to application but there
are some general rules that even the CommandLineParser library follows.
There are generally two types of arguments:
- Explicit arguments that are usually tightly connected to the programs algorithm, function and behavior
- Additional arguments that are used to pass input data, filenames etc. Value of these arguments can for example contain filenames to process.
The main purpose of CommandLineParser library is to handle explicit arguments
. Explicit arguments of the application must be defined by the user of the library.
There are two basic types of explicit arguments - ordinary arguments and arguments with value. If an argument has a value, the value must be the next word after the argument on the command line.
Consider a console application "Finder" that can prints a set of words as it output and they and the interface of the application supports removing the duplicate entries. You may want to introduce "distinct" argument for the application.
You define an ordinary argument "distinct" with short name d. Then user of the application run the application like this:
As you can see, if the argument is used with short name
(resp. long name
), it must be prefixed with single - character (resp. -- prefix).
These arguments can have short names (single character) and long names (one word).
For value arguments
the format stays the same and the argument is followed by the value. Consider another argument for Finder - how deep it should search the subdirectories. This value would be an integer and would be used in this format (suppose short
name s and long name subdirectories):
Finder.exe -s 3
Finder.exe --subdirectories 3
Explicit arguments can be combined and used regardless of order.
are arguments that do not tell the application how to do but do with what. They are distinguished by the parser, stored in separate collection and henceforth ignored.
Additional arguments are recognized by not having neither - nor -- prefix. First argument without the prefix is considered additional argument and all subsequent arguments as well.
Fore example on command line
Finder.exe -s 3 --distinct directory1 directory2 directory3
Arguments directory1 dorectory2 and directory3 are additional arguments.