8 #define SCARAB_API_EXPORTS 18 LOGGER(applog,
"application");
26 f_subcommand_decorators()
66 f_nonoption_kw_args(),
67 f_nonoption_ord_args(),
69 f_app_option_holders()
77 auto t_verbose_callback = [
this](
unsigned a_count )
83 auto t_quiet_callback = [
this](
unsigned a_count )
89 auto t_version_callback = [](int)
94 add_flag_function(
"-V,--version", t_version_callback,
"Print the version message and exit" );
115 f_nonoption_kw_args = t_no_parser.kw_args();
116 f_nonoption_ord_args = t_no_parser.ord_args();
120 LERROR( applog,
"Unable to parse remaining arguments: " << e.
what() );
128 LPROG( applog,
"Final configuration:\n" << f_primary_config );
129 LPROG( applog,
"Ordered args:\n" << f_nonoption_ord_args );
135 LDEBUG( applog,
"first configuration stage" );
136 f_primary_config.merge( f_default_config );
143 LDEBUG( applog,
"second configuration stage" );
144 if( ! f_config_filename.empty() )
147 LDEBUG( applog,
"Loading config file <" << t_config_filepath <<
"> from filename <" << f_config_filename <<
">" );
149 std::unique_ptr< param > t_config_from_file( t_translator.
read_file( t_config_filepath.string() ));
150 if( t_config_from_file == NULL )
152 throw error() <<
"[application] error parsing config file";
154 if( ! t_config_from_file->is_node() )
156 throw error() <<
"[application] configuration file must consist of an object/node";
158 f_primary_config.merge( t_config_from_file->as_node() );
166 LDEBUG( applog,
"third configuration stage" );
167 f_primary_config.merge( f_nonoption_kw_args );
174 std::for_each( f_app_option_holders.begin(), f_app_option_holders.end(),
175 [
this]( std::shared_ptr< app_option_holder > a_ptr ){ a_ptr->add_to_app_options(f_app_options); } );
176 f_primary_config.merge( f_app_options );
213 if( an_offset == 0 )
return;
215 for(
unsigned i_count = 0; i_count < an_offset; ++i_count )
228 if( an_offset == 0 )
return;
230 for(
unsigned i_count = 0; i_count < an_offset; ++i_count )
config_decorator * add_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...
void increase_global_verbosity(unsigned an_offset)
void decrease_global_verbosity(unsigned an_offset)
std::map< verbosity_t, logger::ELevel > verbosity_map_t
verbosity_t get_global_verbosity() const
Get the global verbosity.
path expand_path(const string &a_path)
verbosity_iterator_t f_global_verbosity
std::underlying_type< logger::ELevel >::type verbosity_t
config_decorator(main_app *a_main, app *a_this_app)
void set_global_verbosity(verbosity_t a_verbosity)
Set the global verbosity with the verbosity value.
Option * add_option(std::string option_name, callback_t option_callback, std::string option_description="", bool defaulted=false, std::function< std::string()> func={})
std::shared_ptr< version_semantic > version_semantic_ptr_t
static version_wrapper * get_instance()
void set_version(scarab::version_semantic_ptr_t a_ver)
void set_imp(version_semantic_ptr_t a_imp)
virtual void do_config_stage_4()
Load the application-specific options.
Option * add_flag_function(std::string flag_name, std::function< void(int64_t)> function, std::string flag_description="")
Add option for callback with an integer value.
virtual void do_config_stage_1()
Load default values.
LOGGER(applog, "application")
virtual void do_config_stage_2()
Load the config file.
std::vector< std::string > remaining(bool recurse=false) const
This returns the missing options from the current subcommand.
virtual ~config_decorator()
Adds the ability to create options and subcommands that are tied to a main_app's primary config...
virtual void pre_callback()
Creates a command line program, with very few defaults.
std::vector< conf_dec_ptr_t > f_subcommand_decorators
param_ptr_t read_file(const std::string &a_filename, const param_node &a_options=param_node())
const detail::ExistingFileValidator ExistingFile
Check for existing file (returns error message if check fails)
static verbosity_map_t s_verbosities
This is a successful completion on parsing, supposed to exit.
Primary application class.
Anything that can error in Parse.
App * add_subcommand(std::string subcommand_name="", std::string subcommand_description="")
Add a subcommand. Inherits INHERITABLE and OptionDefaults, and help flag.
App * allow_extras(bool allow=true)
Remove the error when extras are left over on the command line.
Option * check(Validator validator, std::string validator_name="")
Adds a Validator with a built in type name.
virtual void do_config_stage_3()
Load the directly-addressed non-option arguments.
main_app::verbosity_map_t fill_verbosities()
virtual const char * what() const noexcept