34 application::~application()
146 static_cast<void>(argc);
147 static_cast<void>(argv);
192 config.
add(
"config",
"c",
"config",argType::Required,
"",
"config",
false,
"string",
"A local config file");
197 config.
add(
"help",
"h",
"help", argType::True,
"",
"",
false,
"none",
"Print this message and exit");
282 std::cerr <<
"usage: " <<
invokedName <<
" [options] \n";
284 std::cerr <<
" Required arguments:\n";
288 if( clOnlyTargIt->isRequired ==
true)
296 if( targIt->second.isRequired ==
true)
306 std::cerr <<
"\n Optional arguments:\n";
310 if( clOnlyTargIt->isRequired ==
false)
318 if( targIt->second.isRequired ==
false)
A class for managing application configuration and execution.
virtual void setup(int argc, char **argv)
Sets up the application by executing the configuration steps.
std::string invokedName
The name used to invoke this application.
std::string m_configPathCLBase
A base path to add to the CL path. Set in constructor to use.
virtual void setupStandardConfig()
Set up the command-line config option in a standard way.
std::string m_configPathUser
The path to the user's configuration file. If the first character is not '/' or '~',...
std::string m_configPathUser_env
Environment variable to check fo the user config path. Set in constructor to use.
virtual void checkConfig()
Check the config. This is called at the end of setup, before the configuration is cleared.
virtual void setupStandardHelp()
Set up the help an options in a standard way.
bool doHelp
Flag to control whether the help message is printed or not.
virtual void loadBasicConfig()
Load a basic configuration. Can be used in an intermediate derived class to allow its children to use...
int reReadConfig()
Re-read the config stack.
virtual void loadStandardConfig()
Loads the values of "config".
int main(int argc, char **argv)
The application main function.
char ** m_argv
Store argv for later use. E.g. in reReadConfig().
virtual void loadConfig()
Override this function to extract the configured values and set up the application.
int m_argc
Store argc for later use. E.g. in reReadConfig().
void setConfigPathUser(const std::string &s)
Set the user configuration path.
std::string m_configPathLocal_env
Environment variable to check for the local config path. Set in constructor to use.
int m_helpLOColWidth
The width of the long option (–option) column in the help message.
int m_helpCFColWidth
The width of the config file option column in the help message.
bool m_preserveConfig
Flag controlling whether the configuration is cleared before execution. Set in derived constructor.
int m_helpTypeColWidth
The width of the argument type column in the help message.
appConfigurator config
The structure used for parsing and storing the configuration.
bool m_requireConfigPathLocal
Flag controlling whether lack of a local configuration file should be reported.
int m_helpWidth
The total text width available for the help message.
virtual void optionHelp(configTarget &tgt, ioutils::textTable &tt)
Format a configTarget for the help message.
virtual void setDefaults(int argc, char **argv)
Set the default search paths for config files.
virtual void help()
Print a formatted help message, based on the config target inputs.
virtual void setupBasicConfig()
Setup a basic configuration. Can be used in an intermediate derived class to allow its children to us...
virtual int execute()
This function is where the derived class should do its work.
std::string m_configPathCL
The path to a configuration file specified on the command line.
std::string m_configPathGlobal
The path to the gobal configuration file. Set in constructor to use.
virtual void loadStandardHelp()
Loads the value of "help" into doHelp.
std::string m_configPathGlobal_env
Environment variable to check for the global config path. Set in constructor to use.
void setConfigPathGlobal(const std::string &s)
Set the global configuration path.
virtual void setupConfig()
In derived classes this is where the config targets are added to config.
int m_helpSOColWidth
The width of the short option (-o) column in the help message.
std::string m_configPathLocal
The path to a local configuration file. Set in constructor to use.
std::string m_configPathCLBase_env
Environment variable to check for the CL base path. Set in constructor to use.
void setConfigPathLocal(const std::string &s)
Set the local configuration path.
Utilities for working with the environment.
void outPut(iosT &ios)
Output the table to a stream.
std::string getEnv(const std::string &estr)
Return the value of an environment variable.
std::unordered_map< std::string, configTarget > m_targets
The targets are stored in an unordered_map for fast access by key.
int readConfig(const std::string &fname, bool reportFileNotFound=true)
Read and parse a config/ini file, updating the targets.
void add(const configTarget &tgt)
Add a configTarget.
void clear()
Clear the containers and free up the associated memory.
std::list< configTarget > clOnlyTargets
Targets which are only for the command line are stored separately in a list.
void parseCommandLine(int argc, char **argv, const std::string &oneTarget="")
Parse the command line, updating the targets.
std::unordered_map< std::string, configTarget >::iterator targetIterator
Iterator for the targets unordered_map.
std::list< configTarget >::iterator clOnlyTargetIterator
Iterator for the clOnlyTargets list.
std::string helpExplanation
The explanation to display in the help message.
std::string keyword
The config file keyword, read in a "keyword=value" pair.
int orderAdded
The order in which this was added. Useful for displaying help messages.
std::string section
The config file section name, can be empty "".
std::string helpType
The type to display in the help message.
std::string shortOpt
The command-line short option (e.g. "f" for -f)
std::string longOpt
The command-line long option (e.g. "file" for –file)
An ascii table formatter.
std::string m_lineStart
Text to print at the beginning of the line.
std::vector< int > m_colWidths
The widths of each column, not including the separator.
std::string m_rowSep
Text to print between each row.
void addCell(size_t row, size_t col, const std::string &cell)
Add one cell to the table, overwriting if it already exists.
std::string m_colSep
Text to print between each column.
std::vector< std::vector< std::vector< std::string > > > m_rows
The table cells.