The tags defined in this namespace are used as keyword arguments via the Boost.Parameter library.
For the keyword tags, the standard C++ scoping rules apply
namespace fty=senf::console::factory; // Either qualify them with their complete namespace dir.add(..., fty::Command(...) .arg( senf::console::kw::name = "name" ) ); // Or use a namespace alias namespace kw = senf::console::kw; dir.add(..., fty::Command(...) .arg( kw::name = "name" ) ); // Or import the keywords into the current namespace (beware of name collisions) using namespace senf::console::kw; dir.add(..., fty::Command(...) .arg( name = "name" ) );
The second alternative is preferred, the using namespace
directive may be used as long as the keyword names do not clash with another visible symbol.
void command(int); dir.add("command", fty::Command(&command) .arg( kw::name = "name", kw::description = "description", kw::default_value = 1, kw::type_name = "type_name", kw::default_doc = "default_doc" ) );
Usage: command [name:type_name] With: name description default: default_doc
Variables |
|
unspecified_keyword_type | name |
Argument name. |
|
unspecified_keyword_type | description |
One-line argument description. |
|
unspecified_keyword_type | default_value |
Argument default value. |
|
unspecified_keyword_type | type_name |
Type name of this arguments type. |
|
unspecified_keyword_type | default_doc |
String rep of default value. |
|
unspecified_keyword_type | parser |
Argument parser. |
unspecified_keyword_type senf::console::kw:: | ||||
default_doc | ||||
String rep of default value.
By default, the default value is documented by converting the value to it's string representation using the corresponding return value formatter which by default uses boost::lexical_cast
/ iostreams
. The displayed value can be changed by setting this attribute.
Definition at line 372 of file ParsedCommand.hh.
unspecified_keyword_type senf::console::kw:: | ||||
default_value | ||||
Argument default value.
If a default value is specified for an argument, that argument is optional. If an overload is called with fewer arguments than defined, optional values will be used beginning at the last optional argument and going forward until all arguments have values assigned. E.g., an overload with 5 parameters a - e with two defaults attached:
command a:int [b:int] c:int [d:int] e:intWhen calling the overload, the arguments will be assigned in the following way:
command 1 2 |
SyntaxErrorException: invalid number of arguments | ||||
command 1 2 3 |
a = 1 | b = default | c = 2 | d = default | e = 3 |
command 1 2 3 4 |
a = 1 | b = 2 | c = 3 | d = default | e = 4 |
command 1 2 3 4 5 |
a = 1 | b = 2 | c = 3 | d = 4 | e = 5 |
command 1 2 3 4 5 6 |
SyntaxErrorException: invalid number of arguments |
Definition at line 326 of file ParsedCommand.hh.
unspecified_keyword_type senf::console::kw:: | ||||
description | ||||
One-line argument description.
This description is shown in the argument reference. If several overloads have same-named arguments, only one of them should be documented. This documentation then applies to all arguments of that name.
Definition at line 320 of file ParsedCommand.hh.
unspecified_keyword_type senf::console::kw:: | ||||
name | ||||
Argument name.
Sets the displayed name of the argument.
Definition at line 318 of file ParsedCommand.hh.
unspecified_keyword_type senf::console::kw:: | ||||
parser | ||||
Argument parser.
The argument parser is used to convert the argument token list returned by the console/config parser into the appropriate value. If not set explicitly, this conversion is supplied by the ArgumentTraits class.
Setting the parser attribute allows to use a custom parser. The parser is an arbitrary callable object with the signature
void parser(senf::console::ParseCommandInfo::TokensRange const & tokens, value_type & out);
value_type
is the type of the overload parameter. The parser must read and parse the complete tokens range and return the parsed value in out. If the parser fails, it must raise a senf::console::SyntaxErrorException.
Definition at line 379 of file ParsedCommand.hh.
unspecified_keyword_type senf::console::kw:: | ||||
type_name | ||||
Type name of this arguments type.
By default, the type of an argument is extracted from the C++ type name by taking the last component of the fully scoped name. This value can be changed by setting this attribute.
Definition at line 367 of file ParsedCommand.hh.