![]() |
HAL
|
#include <program_options.h>
Public Member Functions | |
ProgramOptions (const std::string &name="") | |
~ProgramOptions ()=default | |
ProgramArguments | parse (int argc, const char *argv[]) |
std::vector< std::string > | get_unknown_arguments () |
bool | is_registered (const std::string &flag) const |
bool | add (const std::string &flag, const std::string &description, const std::initializer_list< std::string > ¶meters={}) |
bool | add (const std::initializer_list< std::string > &flags, const std::string &description, const std::initializer_list< std::string > ¶meters={}) |
bool | add (const ProgramOptions &other_options, const std::string &category="") |
bool | remove (const std::string &flag) |
std::string | get_options_string () const |
std::vector< std::tuple< std::set< std::string >, std::string > > | get_options () const |
Static Public Attributes | |
static const std::string | A_REQUIRED_PARAMETER = "__A_REQUIRED_PARAMETER__" |
constant to specify that a parameter is required and does not have a default value. More... | |
Holds the command line options that can be configured from the command line or at runtime using ProgramArguments
.
Definition at line 47 of file program_options.h.
hal::ProgramOptions::ProgramOptions | ( | const std::string & | name = "" | ) |
Constructor, optionally takes a name for grouping in get_options_string()
[in] | name | - The name of this group of program options. |
Definition at line 17 of file program_options.cpp.
References name.
|
default |
bool hal::ProgramOptions::add | ( | const ProgramOptions & | other_options, |
const std::string & | category = "" |
||
) |
Adds another set of options.
A category can be supplied for grouping in the get_options_string() function.
[in] | other_options | - The set of options to add. |
[in] | category | - A category for the added options. [optional] |
Definition at line 208 of file program_options.cpp.
References log_error.
bool hal::ProgramOptions::add | ( | const std::initializer_list< std::string > & | flags, |
const std::string & | description, | ||
const std::initializer_list< std::string > & | parameters = {} |
||
) |
Adds a new option with a multiple flags.
The size of parameters
is the number of parameters this option gets.
Use ProgramOptions::A_REQUIRED_PARAMETER to set a parameter as required.
The values in parameters
contain default values, which are returned by get_parameter_list() / get_parameter() if the user did not supply parameters himself.
[in] | flags | - The flags activating the option. |
[in] | description | - A description of the option. |
[in] | parameters | - A list of default values for all parameters. [optional] |
Definition at line 134 of file program_options.cpp.
References A_REQUIRED_PARAMETER, is_registered(), log_error, and hal::utils::trim().
bool hal::ProgramOptions::add | ( | const std::string & | flag, |
const std::string & | description, | ||
const std::initializer_list< std::string > & | parameters = {} |
||
) |
Adds a new option with a single flag.
The size of parameters
is the number of parameters this option gets.
Use ProgramOptions::A_REQUIRED_PARAMETER to set a parameter as required.
The values in parameters
contain default values, which are returned by get_parameter_list() / get_parameter() if the user did not supply parameters himself.
[in] | flag | - The flag activating the option. |
[in] | description | - A description of the option. |
[in] | parameters | - A list of default values for all parameters. [optional] |
Definition at line 129 of file program_options.cpp.
Referenced by hal::netlist_writer_manager::get_cli_options(), hal::CliExtensionDataflow::get_cli_options(), and hal::LogManager::get_option_descriptions().
std::vector< std::tuple< std::set< std::string >, std::string > > hal::ProgramOptions::get_options | ( | ) | const |
Returns all options' flags and their description.
Definition at line 285 of file program_options.cpp.
Referenced by hal::LogManager::get_option_descriptions().
std::string hal::ProgramOptions::get_options_string | ( | ) | const |
Returns a nicely formatted string of all options and description.
Includes categorys of added ProgramOptions for grouping.
Useful for "usage" messages.
Definition at line 265 of file program_options.cpp.
Referenced by hal::GuiPluginEntry::updateFromLoaded().
std::vector< std::string > hal::ProgramOptions::get_unknown_arguments | ( | ) |
Returns the command line arguments which could not be parsed.
Only valid after parse() was called.
Definition at line 22 of file program_options.cpp.
bool hal::ProgramOptions::is_registered | ( | const std::string & | flag | ) | const |
Checks whether a flag is already registered for an option.
No flag can be registered twice.
[in] | flag | - The flag to check. |
Definition at line 117 of file program_options.cpp.
Referenced by add().
ProgramArguments hal::ProgramOptions::parse | ( | int | argc, |
const char * | argv[] | ||
) |
Parses the command line arguments into the internal structure.
[in] | argc | - Number of arguments. |
[in] | argv | - Array of arguments. |
Definition at line 27 of file program_options.cpp.
References A_REQUIRED_PARAMETER, control::args, die, and hal::utils::join().
bool hal::ProgramOptions::remove | ( | const std::string & | flag | ) |
Removes a single flag.
If multiple flags for an option exist, the others will still remain available.
[in] | flag | - The flag activating the option. |
Definition at line 237 of file program_options.cpp.
|
static |
constant to specify that a parameter is required and does not have a default value.
Definition at line 51 of file program_options.h.
Referenced by add(), hal::netlist_writer_manager::get_cli_options(), hal::LogManager::get_option_descriptions(), and parse().