8 #define SCARAB_API_EXPORTS 19 LOGGER(applog,
"application");
27 f_subcommand_decorators()
50 f_global_verbosity( 1 ),
51 f_nonoption_kw_args(),
52 f_nonoption_ord_args(),
54 f_app_option_holders()
59 add_option(
"--verbosity", f_global_verbosity,
"Global logger verosity" );
61 auto t_version_callback = [](int)
66 add_flag_function(
"-V,--version", t_version_callback,
"Print the version message and exit" );
89 f_nonoption_kw_args = t_no_parser.kw_args();
90 f_nonoption_ord_args = t_no_parser.ord_args();
94 LERROR( applog,
"Unable to parse remaining arguments: " << e.
what() );
102 LPROG( applog,
"Final configuration:\n" << f_master_config );
103 LPROG( applog,
"Ordered args:\n" << f_nonoption_ord_args );
109 LDEBUG( applog,
"first configuration stage" );
110 f_master_config.merge( f_default_config );
117 LDEBUG( applog,
"second configuration stage" );
118 if( ! f_config_filename.empty() )
121 LDEBUG( applog,
"Loading config file <" << t_config_filepath <<
"> from filename <" << f_config_filename <<
">" );
123 std::unique_ptr< param > t_config_from_file( t_translator.
read_file( t_config_filepath.string() ));
124 if( t_config_from_file == NULL )
126 throw error() <<
"[application] error parsing config file";
128 if( ! t_config_from_file->is_node() )
130 throw error() <<
"[application] configuration file must consist of an object/node";
132 f_master_config.merge( t_config_from_file->as_node() );
140 LDEBUG( applog,
"third configuration stage" );
141 f_master_config.merge( f_nonoption_kw_args );
148 std::for_each( f_app_option_holders.begin(), f_app_option_holders.end(),
149 [
this]( std::shared_ptr< app_option_holder > a_ptr ){ a_ptr->add_to_app_options(f_app_options); } );
150 f_master_config.merge( f_app_options );
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...
path expand_path(const string &a_path)
config_decorator(main_app *a_main, app *a_this_app)
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)
virtual const char * what() const
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.
Contains the logger class and macros, based on Kasper's KLogger class.
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 master 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)
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.