HAL
hal::ProgramOptions Class Reference

#include <program_options.h>

Collaboration diagram for hal::ProgramOptions:
Collaboration graph

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 > &parameters={})
 
bool add (const std::initializer_list< std::string > &flags, const std::string &description, const std::initializer_list< std::string > &parameters={})
 
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...
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ ProgramOptions()

hal::ProgramOptions::ProgramOptions ( const std::string &  name = "")

Constructor, optionally takes a name for grouping in get_options_string()

Parameters
[in]name- The name of this group of program options.

Definition at line 17 of file program_options.cpp.

References name.

◆ ~ProgramOptions()

hal::ProgramOptions::~ProgramOptions ( )
default

Member Function Documentation

◆ add() [1/3]

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.

Parameters
[in]other_options- The set of options to add.
[in]category- A category for the added options. [optional]
Returns
True on success.

Definition at line 208 of file program_options.cpp.

References log_error.

◆ add() [2/3]

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.

Parameters
[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]
Returns
True on success.

Definition at line 134 of file program_options.cpp.

References A_REQUIRED_PARAMETER, is_registered(), log_error, and hal::utils::trim().

◆ add() [3/3]

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.

Parameters
[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]
Returns
True on success.

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().

◆ get_options()

std::vector< std::tuple< std::set< std::string >, std::string > > hal::ProgramOptions::get_options ( ) const

Returns all options' flags and their description.

Returns
A vector of ( (1) a set with all flags of the option, (2) the description of the option).

Definition at line 285 of file program_options.cpp.

Referenced by hal::LogManager::get_option_descriptions().

◆ get_options_string()

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.

Returns
The formatted string.

Definition at line 265 of file program_options.cpp.

Referenced by hal::GuiPluginEntry::updateFromLoaded().

◆ get_unknown_arguments()

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.

Returns
A vector containing all strings which could not be parsed.

Definition at line 22 of file program_options.cpp.

◆ is_registered()

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.

Parameters
[in]flag- The flag to check.
Returns
True if the flag is already registered.

Definition at line 117 of file program_options.cpp.

Referenced by add().

◆ parse()

ProgramArguments hal::ProgramOptions::parse ( int  argc,
const char *  argv[] 
)

Parses the command line arguments into the internal structure.

Parameters
[in]argc- Number of arguments.
[in]argv- Array of arguments.
Returns
The parsed arguments.

Definition at line 27 of file program_options.cpp.

References A_REQUIRED_PARAMETER, control::args, die, and hal::utils::join().

◆ remove()

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.

Parameters
[in]flag- The flag activating the option.
Returns
True if the option was found.

Definition at line 237 of file program_options.cpp.

Member Data Documentation

◆ A_REQUIRED_PARAMETER

const std::string hal::ProgramOptions::A_REQUIRED_PARAMETER = "__A_REQUIRED_PARAMETER__"
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().


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