3.8.0
Freundlich's C++ toolkit
Public Types | Public Member Functions
fcppt::options::commands< OptionsParser, SubCommands > Class Template Reference

Detailed Description

template<typename OptionsParser, typename... SubCommands>
class fcppt::options::commands< OptionsParser, SubCommands >

A parser for multiple sub commands.

A commands parser parses multiple sub commands. Each sub command consists of a parser and a name, i.e. (name_1, parser_1), ..., (name_n, parser_n). The parser first searches for the first argument, ignoring all option names from OptionsParser. If none is found, the parser fails. Otherwise, the first argument is arg, which is then compared to name_1, ..., name_n. If none of these is equal to arg, the parser fails. Otherwise, let arg = name_i, then the OptionsParser is used to parse everything up to the first argument, and parser_i is used to parse everything after.

Warning
Be careful not to include anything other than options or flags in OptionsParser, because otherwise this may lead to very confusing results.
Template Parameters
OptionsParserA parser that should only parse options.

Public Types

using variant_result = fcppt::variant::object< fcppt::options::result_of< SubCommands >... >
 
using result_type = fcppt::record::object< fcppt::record::element< fcppt::options::options_label, fcppt::options::result_of< OptionsParser > >, fcppt::record::element< fcppt::options::sub_command_label, variant_result > >
 

Public Member Functions

template<typename OptionsParserArg , typename... SubCommandsArgs, typename = std::enable_if_t<std::conjunction_v< std::is_same<OptionsParser, fcppt::type_traits::remove_cv_ref_t<OptionsParserArg>>, std::is_same<SubCommands, fcppt::type_traits::remove_cv_ref_t<SubCommandsArgs>>...>>>
 commands (OptionsParserArg &&, SubCommandsArgs &&...)
 Constructs a commands parser. More...
 
fcppt::options::parse_result< result_typeparse (fcppt::options::state &&, fcppt::options::parse_context const &) const
 
fcppt::options::flag_name_set flag_names () const
 
fcppt::options::option_name_set option_names () const
 
fcppt::string usage () const
 

Member Typedef Documentation

◆ result_type

template<typename OptionsParser , typename... SubCommands>
using fcppt::options::commands< OptionsParser, SubCommands >::result_type = fcppt::record::object< fcppt::record:: element<fcppt::options::options_label, fcppt::options::result_of<OptionsParser> >, fcppt::record::element<fcppt::options::sub_command_label, variant_result> >

◆ variant_result

template<typename OptionsParser , typename... SubCommands>
using fcppt::options::commands< OptionsParser, SubCommands >::variant_result = fcppt::variant::object<fcppt::options::result_of<SubCommands>...>

Constructor & Destructor Documentation

◆ commands()

template<typename OptionsParser , typename... SubCommands>
template<typename OptionsParserArg , typename... SubCommandsArgs, typename = std::enable_if_t<std::conjunction_v< std::is_same<OptionsParser, fcppt::type_traits::remove_cv_ref_t<OptionsParserArg>>, std::is_same<SubCommands, fcppt::type_traits::remove_cv_ref_t<SubCommandsArgs>>...>>>
fcppt::options::commands< OptionsParser, SubCommands >::commands ( OptionsParserArg &&  ,
SubCommandsArgs &&  ... 
)
explicit

Constructs a commands parser.

Template Parameters
OptionsParserArgA cv-ref to OptionsParser
SubCommandsArgsCv-refs to SubCommands

Member Function Documentation

◆ flag_names()

template<typename OptionsParser , typename... SubCommands>
fcppt::options::flag_name_set fcppt::options::commands< OptionsParser, SubCommands >::flag_names ( ) const

◆ option_names()

template<typename OptionsParser , typename... SubCommands>
fcppt::options::option_name_set fcppt::options::commands< OptionsParser, SubCommands >::option_names ( ) const

◆ parse()

template<typename OptionsParser , typename... SubCommands>
fcppt::options::parse_result<result_type> fcppt::options::commands< OptionsParser, SubCommands >::parse ( fcppt::options::state &&  ,
fcppt::options::parse_context const &   
) const

◆ usage()

template<typename OptionsParser , typename... SubCommands>
fcppt::string fcppt::options::commands< OptionsParser, SubCommands >::usage ( ) const