Scarab  v3.4.3
Project 8 C++ Utility Library
Public Types | Public Member Functions | Static Public Attributes | Protected Attributes | List of all members
main_app Class Reference

Primary application class. More...

#include <application.hh>

Inheritance diagram for main_app:
Inheritance graph

Public Types

using verbosity_t = std::underlying_type< logger::ELevel >::type
 
using verbosity_map_t = std::map< verbosity_t, logger::ELevel >
 
using verbosity_iterator_t = verbosity_map_t::iterator
 

Public Member Functions

 main_app (bool a_use_config=true)
 
virtual ~main_app ()
 
virtual void pre_callback ()
 
virtual void do_config_stage_1 ()
 Load default values. More...
 
virtual void do_config_stage_2 ()
 Load the config file. More...
 
virtual void do_config_stage_3 ()
 Load the directly-addressed non-option arguments. More...
 
virtual void do_config_stage_4 ()
 Load the application-specific options. More...
 
void set_version (scarab::version_semantic_ptr_t a_ver)
 
 mv_referrable (param_node, primary_config)
 Master configuration tree for the application. More...
 
 mv_referrable (param_node, default_config)
 Default configuration values. More...
 
 mv_referrable_const (std::string, config_filename)
 Configuration file name. More...
 
 mv_referrable (param_node, nonoption_kw_args)
 Keyword configuration values coming from the command line, in the form: config.address=value. More...
 
 mv_referrable (param_array, nonoption_ord_args)
 Ordered configuration values coming in an application-specific order from the command line, in the form: value. More...
 
 mv_referrable (param_node, app_options)
 Application-specific options that are specified using add_config_option() functions. More...
 
 mv_referrable (std::vector< std::shared_ptr< app_option_holder > >, app_option_holders)
 Store the app option holder structs from this app and any subcommands. More...
 
 mv_accessible_noset (bool, use_config)
 
verbosity_t get_global_verbosity () const
 Get the global verbosity. More...
 
void set_global_verbosity (verbosity_t a_verbosity)
 Set the global verbosity with the verbosity value. More...
 
void set_global_verbosity (logger::ELevel a_verbosity)
 Set the global verbosity with the verbosity enum. More...
 
void increase_global_verbosity (unsigned an_offset)
 
void decrease_global_verbosity (unsigned an_offset)
 
- Public Member Functions inherited from config_decorator
 config_decorator (main_app *a_main, app *a_this_app)
 
 config_decorator (const config_decorator &)=delete
 
 config_decorator (config_decorator &&)=delete
 
virtual ~config_decorator ()
 
config_decoratoroperator= (const config_decorator &)=delete
 
config_decoratoroperator= (config_decorator &&)=delete
 
main_appmain () const
 
appthis_app () const
 
config_decoratoradd_config_subcommand (std::string a_subcommand_name, std::string a_description="")
 Add a subcommand that is linked to a particular main_app and can create options that modify that main_app's primary config. More...
 
template<typename T , CLI::enable_if_t< ! CLI::is_vector< T >::value, CLI::detail::enabler > = CLI::detail::dummy>
CLI::Optionadd_config_option (std::string a_name, std::string a_primary_config_addr, std::string a_description="")
 Add an option that gets automatically added to the primary config of a main_app. More...
 
template<typename T , CLI::enable_if_t< ! CLI::is_vector< T >::value, CLI::detail::enabler > = CLI::detail::dummy>
CLI::Optionadd_config_multi_option (std::string a_name, std::string a_primary_config_addr, std::string a_description="")
 Add an option that gets automatically added to the primary config of a main_app. More...
 
template<typename T , CLI::enable_if_t< std::is_integral< T >::value &&! CLI::is_bool< T >::value, CLI::detail::enabler > = CLI::detail::dummy>
CLI::Optionadd_config_flag (std::string a_name, std::string a_primary_config_addr, std::string a_description="")
 
template<typename T , CLI::enable_if_t< CLI::is_bool< T >::value, CLI::detail::enabler > = CLI::detail::dummy>
CLI::Optionadd_config_flag (std::string a_name, std::string a_primary_config_addr, std::string a_description="")
 
- Public Member Functions inherited from App
void _move_option (Option *opt, App *app)
 function that could be used by subclasses of App to shift options around into subcommands More...
 
 App (std::string app_description="", std::string app_name="")
 Create a new program. Pass in the same arguments as main(), along with a help string. More...
 
virtual ~App ()=default
 virtual destructor More...
 
Appcallback (std::function< void()> app_callback)
 
Apppreparse_callback (std::function< void(size_t)> pp_callback)
 
Appname (std::string app_name="")
 Set a name for the app (empty will use parser to set the name) More...
 
Appallow_extras (bool allow=true)
 Remove the error when extras are left over on the command line. More...
 
Apprequired (bool require=true)
 Remove the error when extras are left over on the command line. More...
 
Appdisabled (bool disable=true)
 Disable the subcommand or option group. More...
 
Appdisabled_by_default (bool disable=true)
 Set the subcommand to be disabled by default, so on clear(), at the start of each parse it is disabled. More...
 
Appenabled_by_default (bool enable=true)
 
Appimmediate_callback (bool immediate=true)
 Set the subcommand callback to be executed immediately on subcommand completion. More...
 
Appvalidate_positionals (bool validate=true)
 Set the subcommand to validate positional arguments before assigning. More...
 
Appallow_config_extras (bool allow=true)
 
Appprefix_command (bool allow=true)
 Do not parse anything after the first unrecognized option and return. More...
 
Appignore_case (bool value=true)
 Ignore case. Subcommands inherit value. More...
 
Appallow_windows_style_options (bool value=true)
 Allow windows style options, such as /opt. First matching short or long name used. Subcommands inherit value. More...
 
Apppositionals_at_end (bool value=true)
 Specify that the positional arguments are only at the end of the sequence. More...
 
Appignore_underscore (bool value=true)
 Ignore underscore. Subcommands inherit value. More...
 
Appformatter (std::shared_ptr< FormatterBase > fmt)
 Set the help formatter. More...
 
Appformatter_fn (std::function< std::string(const App *, std::string, AppFormatMode)> fmt)
 Set the help formatter. More...
 
Appconfig_formatter (std::shared_ptr< Config > fmt)
 Set the config formatter. More...
 
bool parsed () const
 Check to see if this subcommand was parsed, true only if received on command line. More...
 
OptionDefaultsoption_defaults ()
 Get the OptionDefault object, to set option defaults. More...
 
Appadd_subcommand (std::string subcommand_name="", std::string subcommand_description="")
 Add a subcommand. Inherits INHERITABLE and OptionDefaults, and help flag. More...
 
Appadd_subcommand (CLI::App_p subcom)
 Add a previously created app as a subcommand. More...
 
bool remove_subcommand (App *subcom)
 Removes a subcommand from the App. Takes a subcommand pointer. Returns true if found and removed. More...
 
Appget_subcommand (App *subcom) const
 
Appget_subcommand (std::string subcom) const
 Check to see if a subcommand is part of this command (text version) More...
 
Appget_subcommand (int index=0) const
 Get a pointer to subcommand by index. More...
 
CLI::App_p get_subcommand_ptr (App *subcom) const
 Check to see if a subcommand is part of this command and get a shared_ptr to it. More...
 
CLI::App_p get_subcommand_ptr (std::string subcom) const
 Check to see if a subcommand is part of this command (text version) More...
 
CLI::App_p get_subcommand_ptr (int index=0) const
 Get an owning pointer to subcommand by index. More...
 
Appget_option_group (std::string group_name) const
 Check to see if an option group is part of this App. More...
 
size_t count () const
 
size_t count_all () const
 
Appgroup (std::string group_name)
 Changes the group membership. More...
 
Apprequire_subcommand ()
 The argumentless form of require subcommand requires 1 or more subcommands. More...
 
Apprequire_subcommand (int value)
 
Apprequire_subcommand (size_t min, size_t max)
 
Apprequire_option ()
 The argumentless form of require option requires 1 or more options be used. More...
 
Apprequire_option (int value)
 
Apprequire_option (size_t min, size_t max)
 
Appfallthrough (bool value=true)
 
 operator bool () const
 
size_t count (std::string option_name) const
 Counts the number of times the given option was passed. More...
 
std::vector< App * > get_subcommands () const
 
std::vector< const App * > get_subcommands (const std::function< bool(const App *)> &filter) const
 
std::vector< App * > get_subcommands (const std::function< bool(App *)> &filter)
 
bool got_subcommand (App *subcom) const
 Check to see if given subcommand was selected. More...
 
bool got_subcommand (std::string subcommand_name) const
 Check with name instead of pointer to see if subcommand was selected. More...
 
Appexcludes (Option *opt)
 Sets excluded options for the subcommand. More...
 
Appexcludes (App *app)
 Sets excluded subcommands for the subcommand. More...
 
bool remove_excludes (Option *opt)
 Removes an option from the excludes list of this subcommand. More...
 
bool remove_excludes (App *app)
 Removes a subcommand from this excludes list of this subcommand. More...
 
std::shared_ptr< FormatterBaseget_formatter () const
 Access the formatter. More...
 
std::shared_ptr< Configget_config_formatter () const
 Access the config formatter. More...
 
std::string get_description () const
 Get the app or subcommand description. More...
 
Appdescription (std::string app_description)
 Set the description of the app. More...
 
std::vector< const Option * > get_options (const std::function< bool(const Option *)> filter={}) const
 Get the list of options (user facing function, so returns raw pointers), has optional filter function. More...
 
Optionget_option_no_throw (std::string option_name) noexcept
 Get an option by name (noexcept non-const version) More...
 
const Optionget_option_no_throw (std::string option_name) const noexcept
 Get an option by name (noexcept const version) More...
 
const Optionget_option (std::string option_name) const
 Get an option by name. More...
 
Optionget_option (std::string option_name)
 Get an option by name (non-const version) More...
 
const Optionoperator[] (const std::string &option_name) const
 Shortcut bracket operator for getting a pointer to an option. More...
 
const Optionoperator[] (const char *option_name) const
 Shortcut bracket operator for getting a pointer to an option. More...
 
bool get_ignore_case () const
 Check the status of ignore_case. More...
 
bool get_ignore_underscore () const
 Check the status of ignore_underscore. More...
 
bool get_fallthrough () const
 Check the status of fallthrough. More...
 
bool get_allow_windows_style_options () const
 Check the status of the allow windows style options. More...
 
bool get_positionals_at_end () const
 Check the status of the allow windows style options. More...
 
const std::string & get_group () const
 Get the group of this subcommand. More...
 
const std::string & get_footer () const
 Get footer. More...
 
size_t get_require_subcommand_min () const
 Get the required min subcommand value. More...
 
size_t get_require_subcommand_max () const
 Get the required max subcommand value. More...
 
size_t get_require_option_min () const
 Get the required min option value. More...
 
size_t get_require_option_max () const
 Get the required max option value. More...
 
bool get_prefix_command () const
 Get the prefix command status. More...
 
bool get_allow_extras () const
 Get the status of allow extras. More...
 
bool get_required () const
 Get the status of required. More...
 
bool get_disabled () const
 Get the status of disabled. More...
 
bool get_immediate_callback () const
 Get the status of disabled. More...
 
bool get_disabled_by_default () const
 Get the status of disabled by default. More...
 
bool get_enabled_by_default () const
 Get the status of disabled by default. More...
 
bool get_validate_positionals () const
 Get the status of validating positionals. More...
 
bool get_allow_config_extras () const
 Get the status of allow extras. More...
 
Optionget_help_ptr ()
 Get a pointer to the help flag. More...
 
const Optionget_help_ptr () const
 Get a pointer to the help flag. (const) More...
 
const Optionget_help_all_ptr () const
 Get a pointer to the help all flag. (const) More...
 
Optionget_config_ptr ()
 Get a pointer to the config option. More...
 
const Optionget_config_ptr () const
 Get a pointer to the config option. (const) More...
 
Appget_parent ()
 Get the parent of this subcommand (or nullptr if master app) More...
 
const Appget_parent () const
 Get the parent of this subcommand (or nullptr if master app) (const version) More...
 
std::string get_name () const
 Get the name of the current app. More...
 
std::string get_display_name () const
 Get a display name for an app. More...
 
bool check_name (std::string name_to_check) const
 Check the name, case insensitive and underscore insensitive if set. More...
 
std::vector< std::string > get_groups () const
 Get the groups available directly from this option (in order) More...
 
const std::vector< Option * > & parse_order () const
 This gets a vector of pointers with the original parse order. More...
 
std::vector< std::string > remaining (bool recurse=false) const
 This returns the missing options from the current subcommand. More...
 
std::vector< std::string > remaining_for_passthrough (bool recurse=false) const
 This returns the missing options in a form ready for processing by another command line program. More...
 
size_t remaining_size (bool recurse=false) const
 This returns the number of remaining options, minus the – separator. More...
 
Appfooter (std::string footer_string)
 Set footer. More...
 
std::string config_to_str (bool default_also=false, bool write_description=false) const
 
std::string help (std::string prev="", AppFormatMode mode=AppFormatMode::Normal) const
 
void clear ()
 Reset the parsed data. More...
 
void parse (int argc, const char *const *argv)
 
void parse (std::string commandline, bool program_name_included=false)
 
void parse (std::vector< std::string > &args)
 
void parse (std::vector< std::string > &&args)
 The real work is done here. Expects a reversed vector. More...
 
void failure_message (std::function< std::string(const App *, const Error &e)> function)
 Provide a function to print a help message. The function gets access to the App pointer and error. More...
 
int exit (const Error &e, std::ostream &out=std::cout, std::ostream &err=std::cerr) const
 Print a nice error message and return the exit code. More...
 
Optionadd_option (std::string option_name, callback_t option_callback, std::string option_description="", bool defaulted=false, std::function< std::string()> func={})
 
template<typename T , enable_if_t<!is_vector< T >::value &!std::is_const< T >::value, detail::enabler > = detail::dummy>
Optionadd_option (std::string option_name, T &variable, std::string option_description="", bool defaulted=false)
 Add option for non-vectors (duplicate copy needed without defaulted to avoid iostream << value) More...
 
template<typename T , enable_if_t<!is_vector< T >::value, detail::enabler > = detail::dummy>
Optionadd_option_function (std::string option_name, const std::function< void(const T &)> &func, std::string option_description="")
 Add option for a callback of a specific type. More...
 
Optionadd_option (std::string option_name)
 Add option with no description or variable assignment. More...
 
template<typename T , enable_if_t< std::is_const< T >::value &&std::is_constructible< std::string, T >::value, detail::enabler > = detail::dummy>
Optionadd_option (std::string option_name, T &option_description)
 Add option with description but with no variable assignment or callback. More...
 
template<typename T >
Optionadd_option (std::string option_name, std::vector< T > &variable, std::string option_description="", bool defaulted=false)
 Add option for vectors. More...
 
template<typename T , enable_if_t< is_vector< T >::value, detail::enabler > = detail::dummy>
Optionadd_option_function (std::string option_name, const std::function< void(const T &)> &func, std::string option_description="")
 Add option for a vector callback of a specific type. More...
 
Optionset_help_flag (std::string flag_name="", const std::string &help_description="")
 Set a help flag, replace the existing one if present. More...
 
Optionset_help_all_flag (std::string help_name="", const std::string &help_description="")
 Set a help all flag, replaced the existing one if present. More...
 
Optionadd_flag (std::string flag_name)
 Add a flag with no description or variable assignment. More...
 
template<typename T , enable_if_t< std::is_const< T >::value &&std::is_constructible< std::string, T >::value, detail::enabler > = detail::dummy>
Optionadd_flag (std::string flag_name, T &flag_description)
 
template<typename T , enable_if_t< std::is_integral< T >::value &&!is_bool< T >::value, detail::enabler > = detail::dummy>
Optionadd_flag (std::string flag_name, T &flag_count, std::string flag_description="")
 
template<typename T , enable_if_t<!is_vector< T >::value &&!std::is_const< T >::value &&(!std::is_integral< T >::value||is_bool< T >::value) &&!std::is_constructible< std::function< void(int)>, T >::value, detail::enabler > = detail::dummy>
Optionadd_flag (std::string flag_name, T &flag_result, std::string flag_description="")
 
template<typename T , enable_if_t<!std::is_assignable< std::function< void(int64_t)>, T >::value, detail::enabler > = detail::dummy>
Optionadd_flag (std::string flag_name, std::vector< T > &flag_results, std::string flag_description="")
 Vector version to capture multiple flags. More...
 
Optionadd_flag_callback (std::string flag_name, std::function< void(void)> function, std::string flag_description="")
 Add option for callback that is triggered with a true flag and takes no arguments. More...
 
Optionadd_flag_function (std::string flag_name, std::function< void(int64_t)> function, std::string flag_description="")
 Add option for callback with an integer value. More...
 
template<typename T >
Optionadd_set (std::string option_name, T &member, std::set< T > options, std::string option_description="")
 Add set of options (No default, temp reference, such as an inline set) DEPRECATED. More...
 
template<typename T >
Optionadd_mutable_set (std::string option_name, T &member, const std::set< T > &options, std::string option_description="")
 Add set of options (No default, set can be changed afterwards - do not destroy the set) DEPRECATED. More...
 
template<typename T >
Optionadd_set (std::string option_name, T &member, std::set< T > options, std::string option_description, bool defaulted)
 Add set of options (with default, static set, such as an inline set) DEPRECATED. More...
 
template<typename T >
Optionadd_mutable_set (std::string option_name, T &member, const std::set< T > &options, std::string option_description, bool defaulted)
 Add set of options (with default, set can be changed afterwards - do not destroy the set) DEPRECATED. More...
 
 __attribute__ ((deprecated("Use ->transform(CLI::IsMember(..., CLI::ignore_case)) instead"))) Option *add_set_ignore_case(std
 Add set of options, string only, ignore case (no default, static set) DEPRECATED. More...
 
 __attribute__ ((deprecated("Use ->transform(CLI::IsMember(..., CLI::ignore_case)) with a (shared) pointer instead"))) Option *add_mutable_set_ignore_case(std
 
 __attribute__ ((deprecated("Use ->transform(CLI::IsMember(..., CLI::ignore_case)) instead"))) Option *add_set_ignore_case(std
 Add set of options, string only, ignore case (default, static set) DEPRECATED. More...
 
 __attribute__ ((deprecated("Use ->transform(CLI::IsMember(...)) with a (shared) pointer instead"))) Option *add_mutable_set_ignore_case(std
 
 __attribute__ ((deprecated("Use ->transform(CLI::IsMember(..., CLI::ignore_underscore)) instead"))) Option *add_set_ignore_underscore(std
 Add set of options, string only, ignore underscore (no default, static set) DEPRECATED. More...
 
 __attribute__ ((deprecated("Use ->transform(CLI::IsMember(..., CLI::ignore_underscore)) with a (shared) pointer instead"))) Option *add_mutable_set_ignore_underscore(std
 
 __attribute__ ((deprecated("Use ->transform(CLI::IsMember(..., CLI::ignore_underscore)) instead"))) Option *add_set_ignore_underscore(std
 Add set of options, string only, ignore underscore (default, static set) DEPRECATED. More...
 
 __attribute__ ((deprecated("Use ->transform(CLI::IsMember(..., CLI::ignore_underscore)) with a (shared) pointer instead"))) Option *add_mutable_set_ignore_underscore(std
 
 __attribute__ ((deprecated("Use ->transform(CLI::IsMember(..., CLI::ignore_case, CLI::ignore_underscore)) instead"))) Option *add_set_ignore_case_underscore(std
 Add set of options, string only, ignore underscore and case (no default, static set) DEPRECATED. More...
 
 __attribute__ ((deprecated("Use ->transform(CLI::IsMember(..., CLI::ignore_case, CLI::ignore_underscore)) with a (shared) pointer instead"))) Option *add_mutable_set_ignore_case_underscore(std
 
 __attribute__ ((deprecated("Use ->transform(CLI::IsMember(..., CLI::ignore_case, CLI::ignore_underscore)) instead"))) Option *add_set_ignore_case_underscore(std
 Add set of options, string only, ignore underscore and case (default, static set) DEPRECATED. More...
 
 __attribute__ ((deprecated("Use ->transform(CLI::IsMember(..., CLI::ignore_case, CLI::ignore_underscore)) with a (shared) pointer instead"))) Option *add_mutable_set_ignore_case_underscore(std
 
template<typename T >
Optionadd_complex (std::string option_name, T &variable, std::string option_description="", bool defaulted=false, std::string label="COMPLEX")
 Add a complex number. More...
 
Optionset_config (std::string option_name="", std::string default_filename="", std::string help_message="Read an ini file", bool config_required=false)
 Set a configuration ini file option, or clear it if no name passed. More...
 
bool remove_option (Option *opt)
 Removes an option from the App. Takes an option pointer. Returns true if found and removed. More...
 
template<typename T = Option_group>
T * add_option_group (std::string group_name, std::string group_description="")
 creates an option group as part of the given app More...
 

Static Public Attributes

static verbosity_map_t s_verbosities
 

Protected Attributes

verbosity_iterator_t f_global_verbosity
 
- Protected Attributes inherited from config_decorator
main_appf_main
 
appf_this
 
std::vector< conf_dec_ptr_tf_subcommand_decorators
 
- Protected Attributes inherited from App
std::string name_
 Subcommand name or program name (from parser if name is empty) More...
 
std::string description_
 Description of the current program/subcommand. More...
 
bool allow_extras_ {false}
 If true, allow extra arguments (ie, don't throw an error). INHERITABLE. More...
 
bool allow_config_extras_ {false}
 If true, allow extra arguments in the ini file (ie, don't throw an error). INHERITABLE. More...
 
bool prefix_command_ {false}
 If true, return immediately on an unrecognized option (implies allow_extras) INHERITABLE. More...
 
bool has_automatic_name_ {false}
 If set to true the name was automatically generated from the command line vs a user set name. More...
 
bool required_ {false}
 If set to true the subcommand is required to be processed and used, ignored for main app. More...
 
bool disabled_ {false}
 If set to true the subcommand is disabled and cannot be used, ignored for main app. More...
 
bool pre_parse_called_ {false}
 Flag indicating that the pre_parse_callback has been triggered. More...
 
bool immediate_callback_ {false}
 
std::function< void(size_t)> pre_parse_callback_
 This is a function that runs prior to the start of parsing. More...
 
std::function< void()> callback_
 This is a function that runs when complete. Great for subcommands. Can throw. More...
 
OptionDefaults option_defaults_
 The default values for options, customizable and changeable INHERITABLE. More...
 
std::vector< Option_poptions_
 The list of options, stored locally. More...
 
std::vector< App_psubcommands_
 Storage for subcommand list. More...
 
bool ignore_case_ {false}
 If true, the program name is not case sensitive INHERITABLE. More...
 
bool ignore_underscore_ {false}
 If true, the program should ignore underscores INHERITABLE. More...
 
bool fallthrough_ {false}
 Allow subcommand fallthrough, so that parent commands can collect commands after subcommand. INHERITABLE. More...
 
bool allow_windows_style_options_
 Allow '/' for options for Windows like options. Defaults to true on Windows, false otherwise. INHERITABLE. More...
 
bool positionals_at_end_ {false}
 specify that positional arguments come at the end of the argument sequence not inheritable More...
 
bool disabled_by_default_ {false}
 If set to true the subcommand will start each parse disabled. More...
 
bool enabled_by_default_ {false}
 If set to true the subcommand will be reenabled at the start of each parse. More...
 
bool validate_positionals_ {false}
 If set to true positional options are validated before assigning INHERITABLE. More...
 
Appparent_ {nullptr}
 A pointer to the parent if this is a subcommand. More...
 
size_t parsed_ = 0
 Counts the number of times this command/subcommand was parsed. More...
 
size_t require_subcommand_min_ = 0
 Minimum required subcommands (not inheritable!) More...
 
size_t require_subcommand_max_ = 0
 Max number of subcommands allowed (parsing stops after this number). 0 is unlimited INHERITABLE. More...
 
size_t require_option_min_ = 0
 Minimum required options (not inheritable!) More...
 
size_t require_option_max_ = 0
 Max number of options allowed. 0 is unlimited (not inheritable) More...
 
std::string group_ {"Subcommands"}
 The group membership INHERITABLE. More...
 
std::string config_name_
 The name of the connected config file. More...
 
bool config_required_ {false}
 True if ini is required (throws if not present), if false simply keep going. More...
 
Optionconfig_ptr_ {nullptr}
 Pointer to the config option. More...
 
std::shared_ptr< Configconfig_formatter_ {new ConfigINI()}
 This is the formatter for help printing. Default provided. INHERITABLE (same pointer) More...
 
std::string footer_
 Footer to put after all options in the help output INHERITABLE. More...
 
Optionhelp_ptr_ {nullptr}
 A pointer to the help flag if there is one INHERITABLE. More...
 
Optionhelp_all_ptr_ {nullptr}
 A pointer to the help all flag if there is one INHERITABLE. More...
 
std::shared_ptr< FormatterBaseformatter_ {new Formatter()}
 This is the formatter for help printing. Default provided. INHERITABLE (same pointer) More...
 
std::function< std::string(const App *, const Error &e)> failure_message_ = FailureMessage::simple
 The error message printing function INHERITABLE. More...
 
missing_t missing_
 
std::vector< Option * > parse_order_
 This is a list of pointers to options with the original parse order. More...
 
std::vector< App * > parsed_subcommands_
 This is a list of the subcommands collected, in order. More...
 
std::set< App * > exclude_subcommands_
 this is a list of subcommands that are exclusionary to this one More...
 
std::set< Option * > exclude_options_
 

Additional Inherited Members

- Protected Types inherited from config_decorator
using conf_dec_ptr_t = std::unique_ptr< config_decorator >
 
- Protected Types inherited from App
using missing_t = std::vector< std::pair< detail::Classifier, std::string > >
 
- Protected Member Functions inherited from App
 App (std::string app_description, std::string app_name, App *parent)
 Special private constructor for subcommand. More...
 
void _validate () const
 
void _configure ()
 
void run_callback ()
 Internal function to run (App) callback, bottom up. More...
 
bool _valid_subcommand (const std::string &current, bool ignore_used=true) const
 Check to see if a subcommand is valid. Give up immediately if subcommand max has been reached. More...
 
detail::Classifier _recognize (const std::string &current, bool ignore_used_subcommands=true) const
 Selects a Classifier enum based on the type of the current argument. More...
 
void _process_ini ()
 Read and process an ini file (main app only) More...
 
void _process_env ()
 Get envname options if not yet passed. Runs on all subcommands. More...
 
void _process_callbacks ()
 Process callbacks. Runs on all subcommands. More...
 
void _process_help_flags (bool trigger_help=false, bool trigger_all_help=false) const
 
void _process_requirements ()
 Verify required options and cross requirements. Subcommands too (only if selected). More...
 
void _process ()
 Process callbacks and such. More...
 
void _process_extras ()
 Throw an error if anything is left over and should not be. More...
 
void _process_extras (std::vector< std::string > &args)
 
void increment_parsed ()
 Internal function to recursively increment the parsed counter on the current app as well unnamed subcommands. More...
 
void _parse (std::vector< std::string > &args)
 Internal parse function. More...
 
void _parse (std::vector< std::string > &&args)
 Internal parse function. More...
 
void _parse_config (std::vector< ConfigItem > &args)
 
bool _parse_single_config (const ConfigItem &item, size_t level=0)
 Fill in a single config option. More...
 
bool _parse_single (std::vector< std::string > &args, bool &positional_only)
 
size_t _count_remaining_positionals (bool required_only=false) const
 Count the required remaining positional arguments. More...
 
bool _has_remaining_positionals () const
 Count the required remaining positional arguments. More...
 
bool _parse_positional (std::vector< std::string > &args)
 
App_find_subcommand (const std::string &subc_name, bool ignore_disabled, bool ignore_used) const noexcept
 
bool _parse_subcommand (std::vector< std::string > &args)
 
bool _parse_arg (std::vector< std::string > &args, detail::Classifier current_type)
 
void _trigger_pre_parse (size_t remaining_args)
 Trigger the pre_parse callback if needed. More...
 
App_get_fallthrough_parent ()
 Get the appropriate parent to fallthrough to which is the first one that has a name or the main app. More...
 
void _move_to_missing (detail::Classifier val_type, const std::string &val)
 Helper function to place extra values in the most appropriate position. More...
 

Detailed Description

Primary application class.

Author
N. S. Oblath
 This class is designed to provide an entry point for an application, and to setup the application's configuration
 based on information provided by the user at the command line.

 Note that there is a constructor option, `use_config`, which allows `main_app` to be used without using the configuration file 
 if it's set to false (the default is `true`). 
 There will not be a `-c` CLI option, and the configuration steps will not be run.  Functionality is much closer 
 to that of `CLI::App` in this case.

 The application's primary "configuration" is in the form of a scarab::param_node object that takes input from
 default values, a configuration file, directly-addressed arguments, and application-specific options.

 The `main_app` class uses and makes available all of the functionality of the CLI11 library, and
 in particular it directly extends the CLI::App class.  Links to documentation on how to use CLI11
 are provided below.

 Basic usage (customized from CLI11's basic usage):

 int main( int argc, char **argv )
 {
     main_app the_main;

Add new options/flags here

Set the default config file the_main.default_config() = t_default_config;

This includes calling application::pre_callback() to finalize the global config CLI11_PARSE( the_main, argc, argv );

return 0; }

Notes on specifying and using command-line arguments:

There are two main types of command-line arguments:

  1. "Options" are named arguments. On the command line they look like -b [value], --broker [value], or -r (flag with no value)
  2. "Non-option" arguments have no name, and typically rely on the order they fall on the command line to interpret their meaning.

Options need to be specified in an application (i.e. CLI11 needs to know about them at compile time). All of the functionality of CLI11 is available when using main_app, so you can create options and flags (options with no values) that do not affect the configuration. Alternatively, main_app provides the ability to define options that are automatically added to the configuration (see below).

Notes for setting the configuration in an application:

Stages for setting the configuration

  1. Default options
  2. Config file
  3. Non-option arguments
  4. Application-specified options

In stage 3, arguments can have two forms:

Application specified options (stage 4) are merged with the config and are separately accessible as app_options. They have to be specified in the application using add_config_option(), which will map the option name to an address in the primary config.

The functionality for each stage is implemented in its own virtual function, so a subclass can customize the procedure as needed.

Example: > my_app -c config.yaml –an_opt 20 nested.value="hello"

What happens:

  1. my_app will have default values hard-coded
  2. File config.yaml will be parsed and merged with the defaults
  3. Configuration nested { value: "hello" } will be merged with the primary config
  4. Option an_opt will set something specified in the config to 20

See CLI11 documentation for the CLI::App class:

There are several test examples that can be used as useful references on different ways that applications can be setup. You'll find them in the scarab/testing/applications directory.

Definition at line 261 of file application.hh.

Member Typedef Documentation

◆ verbosity_iterator_t

using verbosity_iterator_t = verbosity_map_t::iterator

Definition at line 327 of file application.hh.

◆ verbosity_map_t

Definition at line 326 of file application.hh.

◆ verbosity_t

using verbosity_t = std::underlying_type< logger::ELevel >::type

Definition at line 314 of file application.hh.

Constructor & Destructor Documentation

◆ main_app()

main_app ( bool  a_use_config = true)

Definition at line 60 of file application.cc.

◆ ~main_app()

~main_app ( )
virtual

Definition at line 101 of file application.cc.

Member Function Documentation

◆ decrease_global_verbosity()

void decrease_global_verbosity ( unsigned  an_offset)

Definition at line 245 of file application.cc.

◆ do_config_stage_1()

void do_config_stage_1 ( )
virtual

Load default values.

Definition at line 140 of file application.cc.

◆ do_config_stage_2()

void do_config_stage_2 ( )
virtual

Load the config file.

Definition at line 151 of file application.cc.

◆ do_config_stage_3()

void do_config_stage_3 ( )
virtual

Load the directly-addressed non-option arguments.

Definition at line 177 of file application.cc.

◆ do_config_stage_4()

void do_config_stage_4 ( )
virtual

Load the application-specific options.

Definition at line 188 of file application.cc.

◆ get_global_verbosity()

main_app::verbosity_t get_global_verbosity ( ) const

Get the global verbosity.

Definition at line 200 of file application.cc.

◆ increase_global_verbosity()

void increase_global_verbosity ( unsigned  an_offset)

Definition at line 230 of file application.cc.

◆ mv_accessible_noset()

mv_accessible_noset ( bool  ,
use_config   
)

◆ mv_referrable() [1/6]

mv_referrable ( param_node  ,
primary_config   
)

Master configuration tree for the application.

◆ mv_referrable() [2/6]

mv_referrable ( param_node  ,
default_config   
)

Default configuration values.

◆ mv_referrable() [3/6]

mv_referrable ( param_node  ,
nonoption_kw_args   
)

Keyword configuration values coming from the command line, in the form: config.address=value.

◆ mv_referrable() [4/6]

mv_referrable ( param_array  ,
nonoption_ord_args   
)

Ordered configuration values coming in an application-specific order from the command line, in the form: value.

◆ mv_referrable() [5/6]

mv_referrable ( param_node  ,
app_options   
)

Application-specific options that are specified using add_config_option() functions.

◆ mv_referrable() [6/6]

mv_referrable ( std::vector< std::shared_ptr< app_option_holder > >  ,
app_option_holders   
)

Store the app option holder structs from this app and any subcommands.

◆ mv_referrable_const()

mv_referrable_const ( std::string  ,
config_filename   
)

Configuration file name.

◆ pre_callback()

void pre_callback ( )
virtual

parses positional arguments into the global config called after parsing, before running callbacks

Reimplemented from App.

Definition at line 110 of file application.cc.

◆ set_global_verbosity() [1/2]

void set_global_verbosity ( main_app::verbosity_t  a_verbosity)

Set the global verbosity with the verbosity value.

Definition at line 205 of file application.cc.

◆ set_global_verbosity() [2/2]

void set_global_verbosity ( logger::ELevel  a_verbosity)

Set the global verbosity with the verbosity enum.

Definition at line 224 of file application.cc.

◆ set_version()

void set_version ( scarab::version_semantic_ptr_t  a_ver)

Definition at line 105 of file application.cc.

Member Data Documentation

◆ f_global_verbosity

verbosity_iterator_t f_global_verbosity
protected

Definition at line 331 of file application.hh.

◆ s_verbosities

main_app::verbosity_map_t s_verbosities
static

Definition at line 328 of file application.hh.


The documentation for this class was generated from the following files: