Sharg 1.1.2-rc.1
The argument parser for bio-c++ tools.
Loading...
Searching...
No Matches
sharg::detail::format_tdl Class Reference

A generalized format to create different tool description files. More...

#include <sharg/detail/format_tdl.hpp>

+ Inheritance diagram for sharg::detail::format_tdl:

Public Types

enum class  FileFormat { CTD , CWL }
 Supported tool description file formats. More...
 

Public Attributes

std::vector< std::function< void(std::string_view)> > parser_set_up_calls
 Vector of functions that stores all calls except add_positional_option.
 
std::vector< std::function< void(std::string_view)> > positional_option_calls
 Vector of functions that stores add_positional_option calls.
 
unsigned positional_option_count {0}
 Keeps track of the number of positional options.
 
tdl::ToolInfo info
 TDL DS filled with tool meta information.
 
tdl::Node::Children parameters
 all collected parameters
 
FileFormat fileFormat
 Targeted tool description format.
 
parser_meta_data meta
 Stores all meta information about the application.
 

Constructors, destructor and assignment

 format_tdl (FileFormat fileFormat)
 Construct from a file format.
 
 format_tdl (format_tdl const &)=default
 Defaulted.
 
format_tdloperator= (format_tdl const &)=default
 Defaulted.
 
 format_tdl (format_tdl &&)=default
 Defaulted.
 
format_tdloperator= (format_tdl &&)=default
 Defaulted.
 
 ~format_tdl ()=default
 Defaulted.
 
template<typename option_type , typename validator_t >
void add_option (option_type &value, config< validator_t > const &config)
 Adds a sharg::print_list_item call to be evaluated later on.
 
template<typename validator_t >
void add_flag (bool &value, config< validator_t > const &config)
 Adds a sharg::print_list_item call to be evaluated later on.
 
template<typename option_type , typename validator_t >
void add_positional_option (option_type &value, config< validator_t > const &config)
 Adds a sharg::print_list_item call to be evaluated later on.
 
void parse (parser_meta_data &parser_meta, std::vector< std::string > const &executable_name)
 Initiates the printing of the help page to std::cout.
 
void add_section (std::string const &title, bool const advanced_only)
 Adds a print_section call to parser_set_up_calls.
 
void add_subsection (std::string const &title, bool const advanced_only)
 Adds a print_subsection call to parser_set_up_calls.
 
void add_line (std::string const &text, bool is_paragraph, bool const advanced_only)
 Adds a print_line call to parser_set_up_calls.
 
void add_list_item (std::string const &key, std::string const &desc, bool const advanced_only)
 Adds a sharg::print_list_item call to parser_set_up_calls.
 
template<typename validator_t >
void store_help_page_element (std::function< void(std::string_view)> printer, config< validator_t > const &config)
 Adds a function object to parser_set_up_calls if the annotation in spec does not prevent it.
 

Additional Inherited Members

- Static Private Member Functions inherited from sharg::detail::format_base
template<typename value_type >
static std::string get_type_name_as_string (value_type const &)
 Returns the input type as a string (reflection).
 
template<detail::is_container_option container_type>
static std::string get_type_name_as_string (container_type const &)
 Returns the value_type of the input container as a string (reflection).
 
template<typename option_value_type >
static std::string option_type_and_list_info (option_value_type const &value)
 Formats the type of a value for the help page printing.
 
template<detail::is_container_option container_type>
static std::string option_type_and_list_info (container_type const &container)
 Formats the container and its value_type for the help page printing.
 
static std::string prep_id_for_help (char const short_id, std::string const &long_id)
 Formats the option/flag identifier pair for the help page printing.
 
static std::string escape_special_xml_chars (std::string const &original)
 Escapes certain characters for correct output.
 
static std::string expand_multiple_flags (std::string const &flag_cluster)
 Expands multiple one character flag identifiers for pretty help output.
 
template<typename option_type , typename default_type >
static std::string get_default_message (option_type const &option, default_type const &value)
 Returns the default message for the help page.
 

Detailed Description

A generalized format to create different tool description files.

This class allows to create different outputs format. See sharg::detail::format_tdl::FileFormat for available formats.

Member Enumeration Documentation

◆ FileFormat

Supported tool description file formats.

Enumerator
CTD 

Support for CTD format.

CWL 

Support for CWL format.

Constructor & Destructor Documentation

◆ format_tdl()

sharg::detail::format_tdl::format_tdl ( FileFormat fileFormat)
inline

Construct from a file format.

Parameters
fileFormatThe file format.

Member Function Documentation

◆ add_flag()

template<typename validator_t >
void sharg::detail::format_tdl::add_flag ( bool & value,
config< validator_t > const & config )
inline

Adds a sharg::print_list_item call to be evaluated later on.

Parameters
[in,out]valueThe variable which shows if the flag is turned off (default) or on.
[in]configA configuration object to customise the sharg::parser behaviour. See sharg::config.
Exceptions
sharg::design_errorif sharg::parser::parse was already called.
sharg::design_errorif value is true.
sharg::design_errorif the option identifier was already used.
sharg::design_errorif the option identifier is not a valid identifier.

This entity is stable. Since version 1.0.

◆ add_line()

void sharg::detail::format_tdl::add_line ( std::string const & text,
bool is_paragraph,
bool const advanced_only )
inline

Adds a print_line call to parser_set_up_calls.

Parameters
[in]textThe text to print.
[in]is_paragraphWhether to insert as paragraph or just a line (Default: false).
[in]advanced_onlyIf set to true, the section only shows when the user requested the advanced help page.
Exceptions
sharg::design_errorif sharg::parser::parse was already called.

If the line is not a paragraph (false), only one line break is appended, otherwise two line breaks are appended. This only affects the help page and other output formats.

This entity is stable. Since version 1.0.

◆ add_list_item()

void sharg::detail::format_tdl::add_list_item ( std::string const & key,
std::string const & desc,
bool const advanced_only )
inline

Adds a sharg::print_list_item call to parser_set_up_calls.

Parameters
[in]keyThe key of the key-value pair of the list item.
[in]descThe value of the key-value pair of the list item.
[in]advanced_onlyIf set to true, the section only shows when the user requested the advanced help page.
Exceptions
sharg::design_errorif sharg::parser::parse was already called.

Note: This only affects the help page and other output formats.

A list item is composed of a key (key) and value (desc) and usually used for option identifier-description-pairs. E.g.:

-a, --age LONG
Super important integer for age.

This entity is stable. Since version 1.0.

◆ add_option()

template<typename option_type , typename validator_t >
void sharg::detail::format_tdl::add_option ( option_type & value,
config< validator_t > const & config )
inline

Adds a sharg::print_list_item call to be evaluated later on.

Template Parameters
option_typeMust have a formatted input function (stream >> value). If option_type is a container, its value type must have the formatted input function (exception: std::string is not regarded as a container). See FormattedInputFunction .
validator_typeThe type of validator to be applied to the option value. Must model sharg::validator.
Parameters
[in,out]valueThe variable in which to store the given command line argument.
[in]configA configuration object to customise the sharg::parser behaviour. See sharg::config.

The config.validator must be applicable to the given output variable (value).

Exceptions
sharg::design_errorif sharg::parser::parse was already called.
sharg::design_errorif the option is required and has a default_message.
sharg::design_errorif the option identifier was already used.
sharg::design_errorif the option identifier is not a valid identifier.

This entity is stable. Since version 1.0.

◆ add_positional_option()

template<typename option_type , typename validator_t >
void sharg::detail::format_tdl::add_positional_option ( option_type & value,
config< validator_t > const & config )
inline

Adds a sharg::print_list_item call to be evaluated later on.

Template Parameters
option_typeMust have a formatted input function (stream >> value). If option_type is a container, its value type must have the formatted input function (exception: std::string is not regarded as a container). See FormattedInputFunction .
validator_typeThe type of validator to be applied to the option value. Must model sharg::validator.
Parameters
[in,out]valueThe variable in which to store the given command line argument.
[in]configCustomise the sharg::parser behaviour. See sharg::positional_config.
Exceptions
sharg::design_errorif sharg::parser::parse was already called.
sharg::design_errorif the option has a short or long identifier.
sharg::design_errorif the option is advanced or hidden.
sharg::design_errorif the option has a default_message.
sharg::design_errorif there already is a positional list option.
sharg::design_errorif there are subcommands.

The config.validator must be applicable to the given output variable (value).

This entity is stable. Since version 1.0.

◆ add_section()

void sharg::detail::format_tdl::add_section ( std::string const & title,
bool const advanced_only )
inline

Adds a print_section call to parser_set_up_calls.

Parameters
[in]titleThe title of the section.
[in]advanced_onlyIf set to true, the section only shows when the user requested the advanced help page.
Exceptions
sharg::design_errorif sharg::parser::parse was already called.

This only affects the help page and other output formats.

This entity is stable. Since version 1.0.

◆ add_subsection()

void sharg::detail::format_tdl::add_subsection ( std::string const & title,
bool const advanced_only )
inline

Adds a print_subsection call to parser_set_up_calls.

Parameters
[in]titleThe title of the subsection.
[in]advanced_onlyIf set to true, the section only shows when the user requested the advanced help page.
Exceptions
sharg::design_errorif sharg::parser::parse was already called.

This only affects the help page and other output formats.

This entity is stable. Since version 1.0.

◆ parse()

void sharg::detail::format_tdl::parse ( parser_meta_data & parser_meta,
std::vector< std::string > const & executable_name )
inline

Initiates the printing of the help page to std::cout.

Parameters
[in]parser_metaThe meta information that are needed for a detailed help page.
[in]executable_nameA list of arguments that form together the call to the executable. For example: [raptor, build]

◆ store_help_page_element()

template<typename validator_t >
void sharg::detail::format_tdl::store_help_page_element ( std::function< void(std::string_view)> printer,
config< validator_t > const & config )
inlineprivate

Adds a function object to parser_set_up_calls if the annotation in spec does not prevent it.

Parameters
[in]printerThe invokable that, if added to parser_set_up_calls, prints information to the help page.
[in]configThe option specification deciding whether to add the information to the help page.

If spec equals sharg::option_spec::hidden, the information is never added to the help page.

Member Data Documentation

◆ meta

parser_meta_data sharg::detail::format_tdl::meta

Stores all meta information about the application.

This needs to be a member of format_parse, because it needs to present (not filled) when the parser_set_up_calls vector is filled, since all printing functions need some meta information. The member variable itself is filled when copied over from the argument_parser when calling format_parse::parse. That way all the information needed are there, when the actual printing starts.

This function is not private because it is needed for short but nicely formatted (error) output to the command line.


The documentation for this class was generated from the following file:
Hide me