|
kaycxx-cli
C++ CLI library
|
command::parse accepts argc and argv directly from main and returns the parsed arguments.
The returned args object is movable but not copyable. Keep it by value with auto.
Flags and options are parsed immediately. Unknown switches, missing or invalid option values, and conflicting actions therefore produce an error during parse().
Positional arguments are retained as strings and validated lazily. Accessing any positional parameter through args::get() or args::has() validates and converts all positional parameters once.
Call args::validate() to validate positional parameters without reading one of them.
This is useful when a command defines positional parameters but does not otherwise access every execution path through their handles. Calling validate() repeatedly has no effect after the first successful validation.
Flags, options, and positional arguments may be freely mixed. -- ends switch parsing. Every following value is positional even when it begins with -.
Invalid command lines throw parse_error. Switch errors are thrown by command::parse(). Missing, unexpected, or invalid positional parameters are thrown when positional validation is first triggered.
Catch the exception at the application boundary to produce a concise command-line error and nonzero exit code.