Clingo
|
Object to add command-line options. More...
#include <app.hh>
Public Types | |
using | Parser = std::function< bool(std::string_view value)> |
An option parser. | |
using | ParserList = std::forward_list< Parser > |
A list of option parsers. | |
Public Member Functions | |
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. | |
Friends | |
auto | c_cast (Options const &x) -> clingo_options_t * |
Convert the class to it's underlying C type. | |
Object to add command-line options.
using Clingo::Options::Parser = std::function<bool(std::string_view value)> |
An option parser.
The function takes the value to parse and returns whether the value has been parsed successfully.
|
inline |
Construct an options object.
For internal use.
opts | the corresponding C type |
parsers | a list to store option parsers in |
|
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.
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 |
|
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}
.
group | the section in the help output |
option | the option specification |
description | the option description |
flag | a reference to the semantic value |