Initializes the list of source arguments.
Resets the list of available source arguments.
Returns the list of unprocessed arguments, including the app arguments and resets the list of available source arguments.
Returns the list of unprocessed arguments, ignoring the app arguments, and resets the list of available source arguments.
Returns the list of app args.
Checks if the app arguments are present.
Checks if the --version argument is present on the first position in the list.
Returns the list of all options recognized.
Using CommandArgs
/// It should not find the app version for an empty arg list assert(new CommandArgs([]).hasAppVersion == false); /// It should find the app version when `--version` is the first arg assert(new CommandArgs(["--version"]).hasAppVersion == true); /// It should not find the app version when `--version` is the second arg assert(new CommandArgs(["a", "--version"]).hasAppVersion == false); /// It returns an empty app arg list when `--` arg is missing assert(new CommandArgs(["1", "2"]).appArgs == []); /// It returns an empty app arg list when `--` arg is missing assert(new CommandArgs(["1", "2"]).appArgs == []); /// It returns app args set after "--" assert(new CommandArgs(["1", "2", "--", "a"]).appArgs == ["a"]); assert(new CommandArgs(["1", "2", "--"]).appArgs == []); assert(new CommandArgs(["--"]).appArgs == []); assert(new CommandArgs(["--", "a"]).appArgs == ["a"]); /// It returns the list of all args when no args are processed assert(new CommandArgs(["1", "2", "--", "a"]).extractAllRemainingArgs == ["1", "2", "--", "a"]);
It removes the extracted args
auto args = new CommandArgs(["-a", "-b", "--", "-c"]); bool value; args.getopt("b", &value, [""]); assert(args.extractAllRemainingArgs == ["-a", "--", "-c"]);
It should not be able to remove app args
auto args = new CommandArgs(["-a", "-b", "--", "-c"]); bool value; args.getopt("-c", &value, [""]); assert(!value); assert(args.extractAllRemainingArgs == ["-a", "-b", "--", "-c"]);
Encapsulates a set of application arguments.
This class serves two purposes. The first is to provide an API for parsing command line arguments (getopt). At the same time it records all calls to getopt and provides a list of all possible options using the recognizedArgs property.