Sharg 1.1.0
The argument parser for bio-c++ tools.
 
Loading...
Searching...
No Matches
sharg::config< validator_t > Struct Template Reference

Option struct that is passed to the sharg::parser::add_option() function. More...

#include <sharg/config.hpp>

Public Attributes

char short_id {'\0'}
 The short identifier for the option (e.g. 'a', making the option callable via -a). More...
 
std::string long_id {}
 The long identifier for the option (e.g. "age", making the option callable via --age). More...
 
std::string description {}
 The description to be shown on any (exported) help page. More...
 
std::string default_message {}
 The default message to be shown on any (exported) help page. More...
 
bool advanced {false}
 Whether the option should only be displayed on the advanced help page. More...
 
bool hidden {false}
 Whether the option should be hidden. More...
 
bool required {false}
 Whether the option is required. More...
 
validator_t validator {}
 A sharg::validator that verifies the value after parsing (callable). More...
 

Detailed Description

template<typename validator_t = detail::default_validator>
struct sharg::config< validator_t >

Option struct that is passed to the sharg::parser::add_option() function.

The following table gives an overview about which parameters are valid for which type of option added to the parser. Please see the individual entities for detailed documentation.

  • - Parameter can be set for this type of option
  • (✓) - Parameter can be set but is not indented for this type of option
  • X - Setting this parameter for this type of option raises a sharg::design_error
Parameter option ( -a/--all) flag (-f) positional_option (foo)
sharg::config::short_id X
sharg::config::long_id X
sharg::config::description
sharg::config::default_message X X
sharg::config::advanced X
sharg::config::hidden X
sharg::config::required (✓)
sharg::config::validator (✓)

This entity is stable. Since version 1.0.

Member Data Documentation

◆ advanced

template<typename validator_t = detail::default_validator>
bool sharg::config< validator_t >::advanced {false}

Whether the option should only be displayed on the advanced help page.

This is only relevant for the help page printed on the command line. If set to true, the option will only be displayed when the user requests the advanced help via ./executable --advanced-help or ./executable -hh.

This can help to not overwhelm the user with parameters but still provide an extensive interface of your application.

When information are exported with --export-help, advanced options are always shown.

Attention
This parameter cannot be set for positional options added with sharg::parser::add_positional_option and will trigger a sharg::design_error.

This entity is stable. Since version 1.0.

◆ default_message

template<typename validator_t = detail::default_validator>
std::string sharg::config< validator_t >::default_message {}

The default message to be shown on any (exported) help page.

"Default: " will be prepended. "." will be appended.

Example

parser.add_option(j, sharg::config{.short_id = 'j’. default_message = "Same as -i"})` will result in the help page looking like this:

-j (signed 32 bit integer)
Default: Same as -i.
Attention
Not allowed for required options, flags, and positional options.

This entity is stable. Since version 1.0.

◆ description

template<typename validator_t = detail::default_validator>
std::string sharg::config< validator_t >::description {}

The description to be shown on any (exported) help page.

This entity is stable. Since version 1.0.

◆ hidden

template<typename validator_t = detail::default_validator>
bool sharg::config< validator_t >::hidden {false}

Whether the option should be hidden.

If set to true, the option will not be displayed on any help page; Neither when calling ./executable --help, nor when exported with --export-help.

Attention
This parameter cannot be set for positional options added with sharg::parser::add_positional_option and will trigger a sharg::design_error.

This entity is stable. Since version 1.0.

◆ long_id

template<typename validator_t = detail::default_validator>
std::string sharg::config< validator_t >::long_id {}

The long identifier for the option (e.g. "age", making the option callable via --age).

Attention
This parameter cannot be set for positional options added with sharg::parser::add_positional_option and will trigger a sharg::design_error.

This entity is stable. Since version 1.0.

◆ required

template<typename validator_t = detail::default_validator>
bool sharg::config< validator_t >::required {false}

Whether the option is required.

If set to true and the user does not provide the respective option on the command line, the argument_parser will automatically detect this and throw a sharg::invalid_argument exception.

Attention
This parameter cannot be set for positional options added with sharg::parser::add_positional_option and will trigger a sharg::design_error.

This entity is stable. Since version 1.0.

◆ short_id

template<typename validator_t = detail::default_validator>
char sharg::config< validator_t >::short_id {'\0'}

The short identifier for the option (e.g. 'a', making the option callable via -a).

Attention
This parameter cannot be set for positional options added with sharg::parser::add_positional_option and will trigger a sharg::design_error.

This entity is stable. Since version 1.0.

◆ validator

template<typename validator_t = detail::default_validator>
validator_t sharg::config< validator_t >::validator {}

A sharg::validator that verifies the value after parsing (callable).

This entity is stable. Since version 1.0.


The documentation for this struct was generated from the following file: