void setVersion(const char* version);Set the version message.
const std::string& getVersion() const;Get the version message.
Args& setAlternative(bool alternivative = true);Enable parsing to accept long options with only one '-' character.
bool isAlternative() const;Get the status of alternative.
Args& setAbbreviate(bool abbreviate = true);Enable parsing to accept abbreviated long options (e.g., --ver matches --version).
When enabled, long options (starting with --) can be specified using any unambiguous prefix. If the abbreviation matches multiple options, a ParseArgumentException is thrown with details about the ambiguous matches. Exact matches always take precedence over abbreviations.
Example:
Args args;
args.addArgument("--version");
args.addArgument("--verbose");
args.setAbbreviate();
// --vers matches --version (unambiguous)
// --verb matches --verbose (unambiguous)
// --ver throws exception (ambiguous: matches both --version and --verbose)bool isAbbreviate() const;Get the status of abbreviated options.
Args& setStrict(bool strict = true);Throw exception if not all arguments are used; otherwise, you can take additional arguments with getAdditionalArguments method.
bool isStrict() const;Get the status of strict.
Args& setHelpException(bool helpException = true);Throw a HelpException when help action is present in arguments; otherwise, exit(0) after outputting usage to stdout.
bool isHelpException() const;Get the status of helpException.
Args& setVersionException(bool versionException = true);Throw a VersionException when version action is present in arguments; otherwise, exit(0) after outputting usage to stdout.
bool isVersionException() const;Get the status of versionException.
void setBinaryName(const char* binaryName);Set the binary name.
const std::string& getBinaryName() const;Get the binary name.
bool argumentExists(const std::string& nameOrFlag) const;Check if name or flag is added with addArgument method.
const Argument& getArgument(const std::string& nameOrFlag) const;
const Argument& operator[](const std::string& nameOrFlag) constGet the const argument from name or flag.
| Methods | |||
|---|---|---|---|
| count | isExists | isRequired | getNargs |
| getHelp | getMetavar | getNameOrFlags | getDefaults |
| getAction | getString | getNumber | operator-bool |
| operator-string |
const std::vector<std::string>& getAdditionalArguments() const;Get the additional arguments after parseArguments method if strict mode is not activated.
void parseArguments(int argc, char* argv[]);Convert argument strings to objects and assign them as attributes of the args map. Previous calls to addArgument determine exactly what objects are created and how they are assigned.
| Methods | |
|---|---|
| setStrict | setAlternative |
| setAbbreviate | setHelpException |
| setVersionException |
Argument& addArgument(const Vector& nameOrFlags);Define how a single command-line argument should be parsed.
Example:
Args args;
args.addArgument({"-a", "-b"});
// args.addArgument(args.vector("-a", "-b")); // C++98
args.addArgument("-c");
args.addArgument("ARG");| Methods | ||
|---|---|---|
| flag | action | help |
| required | metavar | nargs |
| defaults | valid | dest |
Argument& updateArgument(const std::string& nameOrFlag);Get the ref. of argument from name or flag.
void removeArguments(const Vector& nameOrFlags);Remove previously added arguments.
void clear();Clear and reset with default values.