Yagol is a C++ library that processes
configuration input: command-line options,
environment variables, and resource files. Its usage
is as follows:
string user("jrandom");
int size(17);
bool readonly(false);
vector dimensions;
dimensions.push_back(0);
dimensions.push_back(10);
dimensions.push_back(0);
dimensions.push_back(20);
const int appSettings = yagol::AppOptionSet::STRICT_ARGUMENTS | yagol::AppOptionSet::HELP_ON_ERROR;
yagol::AppOptionSet opts(appSettings, "myapp", "my interesting application.");
opts.addOption("user", "The user of the software", &user);
opts.addOption("size", "The size of the something", &size);
opts.addOption("readonly", "Whether to read, and not write", &readonly);
opts.addOption("dimensions", "The geometrical dimensions", &dimensions);
opts.process(argc, argv);
// unused arguments
vector unused = options.getUnprocessedArgs();
That block of code:
- sets default values for application variables
- creates the Yagol option processor, saying
that command-line arguments that look like options
should be treated as errors if not found; and that in
the event of user error (invalid data, bad option), the
help/usage statement should be displayed.
- creates a list of options, each with their
tag (e.g., "--user"), their description, and the
variable to which they are tied
- processes the options. At the end of this,
the user, size, etc., variables will
have the values provided in the command-line arguments,
or they will retain their default values.
- gets the unprocessed ("unconsumed")
command-line arguments
The user interface would then be as follows. To
get the help/usage statement:
% myapp --help
Usage: myapp
My interesting application.
Options:
--user The user of the software (default = "jrandom")
--size The size of the something (default = 17)
--readonly Whether to read, and not write (default = false)
--dimensions The geometrical dimensions (default = 0, 10, 0, 20)
Setting the variables:
% myapp --user george --size 4 --readonly --dimensions 100 24000 400 48000 --end-of-dimensions
Setting the same values, but using shorter names.
Options may be abbreviated to the point that they
are unique, compared to any other option.
% myapp --u george --s 4 --r --dim 100 24000 400 48000 --end-of-dim
Boolean options may be given 'false' values by
using the form --no<name>:
% myapp --noreadonly
See intro.html for more.
|