Object to add command-line options.
More...
#include <app.hh>
|
using | Parser = std::function< void(std::string_view value)> |
| An option parser.
|
|
using | ParserList = std::forward_list< Parser > |
| A list of option parsers.
|
|
|
| Options (clingo_options_t *opts, ParserList &parsers) |
| Construct an options object.
|
|
void | add (std::string_view group, std::string_view option, std::string_view description, Parser parser, bool multi=false, std::optional< std::string_view > argument=std::nullopt) |
| Add an option that is processed with a custom parser.
|
|
void | add_flag (std::string_view group, std::string_view option, std::string_view description, bool &flag) |
| Add an option that is a simple flag.
|
|
Object to add command-line options.
◆ Parser
An option parser.
The function takes the value to parse and returns whether the value has been parsed successfully.
◆ Options()
Construct an options object.
For internal use.
- Parameters
-
opts | the corresponding C type |
parsers | a list to store option parsers in |
◆ add()
void Clingo::Options::add |
( |
std::string_view |
group, |
|
|
std::string_view |
option, |
|
|
std::string_view |
description, |
|
|
Parser |
parser, |
|
|
bool |
multi = false , |
|
|
std::optional< std::string_view > |
argument = std::nullopt |
|
) |
| |
|
inline |
Add an option that is processed with a custom parser.
Note that the parser that the parse is responsible to store the semantic value.
Parameter option specifies the name(s) of the option. For example, "-p,ping" adds the short option "-p" and its long form "--ping". It is also possible to associate an option with a help level by prepending "@l" to the option specification. Options with a level greater than zero are only shown if the argument to help is greater or equal to l.
- Parameters
-
group | the section in the help output |
option | the option specification |
description | the option description |
parser | a parser callback |
multi | whether the option can be specified multiple times |
argument | the value placeholder for the help output |
◆ add_flag()
void Clingo::Options::add_flag |
( |
std::string_view |
group, |
|
|
std::string_view |
option, |
|
|
std::string_view |
description, |
|
|
bool & |
flag |
|
) |
| |
|
inline |
Add an option that is a simple flag.
This function provides a simpler alternative to Options::add() to add flags, which do not take values. When the flag appears on the command line, the target parameter is set to true. Explicit values can also be provided using --flag={yes|no}
.
- Parameters
-
group | the section in the help output |
option | the option specification |
description | the option description |
flag | a reference to the semantic value |
The documentation for this class was generated from the following file: