YesChief!
C++ argv parser
|
#include <yeschief.h>
Public Member Functions | |
CLI (std::string name, std::string description) | |
auto | addCommand (Command *command) -> CLI & |
auto | addGroup (const std::string &name) -> OptionGroup & |
template<typename T = bool> | |
auto | addOption (const std::string &name, const std::string &description, const OptionConfiguration &configuration={}) -> CLI & |
auto | help (std::ostream &out=std::cout) const -> void |
template<typename... Tail> | |
auto | parsePositional (const std::string &option_name, Tail &&...options) -> void |
auto | run (int argc, char **argv) const -> std::expected< CLIResults, Fault > |
Main class of the library. It represents the program itself and manage options and commands
yeschief::CLI::CLI | ( | std::string | name, |
std::string | description ) |
name | Name of your program |
description | Description of your program |
|
nodiscard |
Add a group of options to your program. You can then add options to your group the exact same way you add them to the current class
name | Name of the group |
auto yeschief::CLI::addOption | ( | const std::string & | name, |
const std::string & | description, | ||
const OptionConfiguration & | configuration = {} ) -> CLI & |
Add an option to your program.
The name of the option can be written in 2 ways:
--name
--name
and -n
For the second way, the format should always be <long>,<short>
. For the long name you can have any length but the short name must be only 1 letter
name | Name of the option |
description | Description of the option |
configuration | Advanced configuration |
auto yeschief::CLI::help | ( | std::ostream & | out = std::cout | ) | const -> void |
Display a help message built from defined options or commands with this template:
To see example of outputs, please refer to the usage documentation: Usage documentation
out | Out stream on which help message is printed (default to console output STDOUT) |
auto yeschief::CLI::parsePositional | ( | const std::string & | option_name, |
Tail &&... | options ) -> void |
Allow to set some options as positional arguments. This way the user will no longer need to use option name to set its value
Please note that if an option is repeatable it must be placed as the last one
option_name | |
options | List of options names to parse as positional arguments |
auto yeschief::CLI::run | ( | int | argc, |
char ** | argv ) const -> std::expected< CLIResults, Fault > |
Parse argv against defined options and commands.
In both case if something went wrong during argv parsing, the method will return a Fault with the corresponding message
argc | Count of argument |
argv | Array of argument |