Class CliArgs
Defined in File CliArgs.hpp
Class Documentation
-
class CliArgs
Table with which to specify and parse command-line arguments.
An application developer can specify expected options using a terse syntax (using the keyword aggregate construction for each Option):
CliArgs args{{.name = {"--opt1"}, .help = "an option with an argument"}, {.name = {"--opt2", "-o"}, .help = "An option with an argument (and a short-hand)", .type = ArgType::Integer, .defaults = 0}, {.name = {"--flag1", "-f"}, .help = "A flag option (no argument)", .flag = true}};
- Todo:
Allow option grouping for a more expressive help description.
Note
The
{"--help", "-h"}argument is added automatically. When it is parsed from the command line. The help description will be printed and the application will exit.Note
The usage syntax is intended to be similar to ArgParse.jl.
Unnamed Group
-
template<typename T, std::size_t N>
inline std::array<T, N> get(const std::string &name) const Alternative syntax (see ArgVector::as)
Public Functions
-
explicit CliArgs(std::initializer_list<Option> args)
Construct with braced list (see class description)
-
~CliArgs()
Destructor.
-
void parseArgs(int argc, const char *argv[])
Parse command-line arguments using existing specification.
-
void printUsage(std::ostream &os = std::cout) const
Print one-line application usage expression.
-
void printHelp(std::ostream &os = std::cout) const
Print help description. Includes one-line usage expression and a list of all expected options.
-
const std::string &getAppName() const
Executable name (known only after calling parseArgs())