Skip to content

Latest commit

 

History

History
227 lines (151 loc) · 4.82 KB

File metadata and controls

227 lines (151 loc) · 4.82 KB

Args

setVersion

void setVersion(const char* version);

Set the version message.

getVersion

const std::string& getVersion() const;

Get the version message.

setAlternative

Args& setAlternative(bool alternivative = true);

Enable parsing to accept long options with only one '-' character.

isAlternative

bool isAlternative() const;

Get the status of alternative.

setAbbreviate

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)

isAbbreviate

bool isAbbreviate() const;

Get the status of abbreviated options.

setStrict

Args& setStrict(bool strict = true);

Throw exception if not all arguments are used; otherwise, you can take additional arguments with getAdditionalArguments method.

isStrict

bool isStrict() const;

Get the status of strict.

setHelpException

Args& setHelpException(bool helpException = true);

Throw a HelpException when help action is present in arguments; otherwise, exit(0) after outputting usage to stdout.

isHelpException

bool isHelpException() const;

Get the status of helpException.

setVersionException

Args& setVersionException(bool versionException = true);

Throw a VersionException when version action is present in arguments; otherwise, exit(0) after outputting usage to stdout.

isVersionException

bool isVersionException() const;

Get the status of versionException.

setBinaryName

void setBinaryName(const char* binaryName);

Set the binary name.

getBinaryName

const std::string& getBinaryName() const;

Get the binary name.

argumentExists

bool argumentExists(const std::string& nameOrFlag) const;

Check if name or flag is added with addArgument method.

getArgument

const Argument& getArgument(const std::string& nameOrFlag) const;
const Argument& operator[](const std::string& nameOrFlag) const

Get the const argument from name or flag.

Access

Methods
count isExists isRequired getNargs
getHelp getMetavar getNameOrFlags getDefaults
getAction getString getNumber operator-bool
operator-string

getAdditionalArguments

const std::vector<std::string>& getAdditionalArguments() const;

Get the additional arguments after parseArguments method if strict mode is not activated.

parseArguments

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.

Parse Options

Methods
setStrict setAlternative
setAbbreviate setHelpException
setVersionException

addArgument

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");

Definitions

Methods
flag action help
required metavar nargs
defaults valid dest

updateArgument

Argument& updateArgument(const std::string& nameOrFlag);

Get the ref. of argument from name or flag.

removeArguments

void removeArguments(const Vector& nameOrFlags);

Remove previously added arguments.

clear

void clear();

Clear and reset with default values.