Argument& flag(const char* flag__);Add flag to argument object.
Example:
Args args;
args.addArgument("-f").flag("--foo");Argument& action(enum Action::eAction action__);Add an action when this argument is encountered at the command line.
Action list:
This just stores the argument’s value. This is the default action.
Example at examples.md/none.
This stores a list, and appends each argument value to the list. It is useful to allow an option to be specified multiple times. If the default value is non-empty, the default elements will be present in the parsed value for the option, with any values from the command line appended after those default values.
Example at examples.md/append.
This stores a list, and extends each argument value to the list.
Example at examples.md/extend.
This is used to create the help flag. Example at examples.md/help.
This stores a list.
Example at examples.md/infinite.
This is used to store the value false.
Example at examples.md/storefalse.
This is used to store the value true.
Example at examples.md/storetrue.
This is used to define the version flag. Example at examples.md/version.
Argument& help(const char* help__);Set the help description message for this argument.
Argument& required(bool required__);Whether or not the command-line argument may be omitted.
Argument& metavar(const char* metavar__);A name for the argument in usage messages.
Argument& nargs(std::size_t nargs__);The number of command-line arguments that should be consumed by this object.
Argument& defaults(const Vector& defaults__);Define the defaults string values.
Argument& valid(IValid* pValid, bool isDeletable = true);You can check format of argument with IValid interface.
Example of Custom Valid at examples.md/custom-valid-transform.
args.addArgument("--arg").valid(new blet::Args::ValidNumber());Check if arguments are number.
args.addArgument("--arg").valid(new blet::Args::ValidMinMax(0, 100));Check if arguments are number and if in range of min-max.
args.addArgument("--arg").valid(new blet::Args::ValidChoise(args.vector("foo", "bar")));Check if arguments are in choise.
args.addArgument("--arg").valid(new blet::Args::ValidPath());
args.addArgument("--arg").valid(new blet::Args::ValidPath(blet::Args::ValidPath::IS_DIR));
args.addArgument("--arg").valid(new blet::Args::ValidPath(blet::Args::ValidPath::IS_FILE));Check if arguments are valid path/dir/file.
template<typename T>
Argument& dest(std::vector<std::vector<T> >& dest, void (*toDest)(std::vector<std::vector<T> >& dest, bool isExist, const std::vector<std::vector<std::string> >& arguments) = NULL);
template<typename T>
Argument& dest(std::vector<T>& dest, void (*toDest)(std::vector<T>& dest, bool isExist, const std::vector<std::string>& arguments) = NULL);
template<typename T>
Argument& dest(T& dest, void (*toDest)(T& dest, bool isExist, const std::string& argument) = NULL);Define a reference of object for insert the value after parseArguments method.
Action can be changed by toDest parameter with your function.
unsigned long value;
args.addArgument("--arg").dest(value);Examples at dest.md.
std::string getString() const;Get the string format of this argument.
const std::string& getDefault() const;Get the default value of argument.
bool isNumber() const;Check if this argument is a number ("1234aaa" is true with 1234 like number).
double getNumber() const;Get Number if isNumber.
bool isExists() const;After parseArguments method check if this argument is present in argv.
bool isRequired() const;Get required option.
std::size_t count() const;After parseArguments method check if number of this argument in argv.
std::size_t getNargs() const;Get nargs option.
const std::string& getHelp() const;Get help option.
const std::string& getMetavar() const;Get metavar option.
const std::vector<std::string>& getNameOrFlags() const;Get the name or flag(s) of this argument.
const std::vector<std::string>& getDefaults() constGet the default(s) value(s) of this argument.
Action::eAction getAction() const;Get action option.
operator bool() const;Operator constructor bool, check if argument object isExists.
For action STORE_FALSE the effect is inversed.
Example:
if (args["--option"]) { // call operator bool()
std::cout << args["--option"] << std::endl;
}operator std::string() const;Call getString method.
Example:
std::string option = args["--option"];operator std::vector<std::string>() const;If the argument object contains a lot of one argument, you can get a std::vector of std::string.
Example:
std::vector<std::string> options = args["--options"];operator std::vector<std::vector<std::string> >() const;If the argument object contains a lot of one argument with number of argument (nargs) bigger than one, you can get a std::vector of std::vector of std::string.
Example:
std::vector<std::vector<std::string> > options = args["--options"];template<typename T>
operator T() const;Call the getNumber method with your custom type.
Example:
double option = args["--option"];