Specialization of abstract interface class ConfigurationPlugin, which takes all command line parameters in the constructor and reads variable values from those parameters on request. Its priority value usually is Priorities::CLI , which is higher than all other default plug-ins provided.
Variable categories are used as a prefix together with an underscore '_'
. This means, if variable LOCALE in category ALIB is accessed, the command line parameter –ALIB_LOCALE=xyz is read.
Category and Variable names are insensitive in respect to character case.
Command line variables may be passed with either one hyphen ('-') or two ('–'). Both are accepted.
An application can specify one or more "default categories" by adding their string names to public field DefaultCategories. Variables of these categories are recognized by the plug-in also when given without the prefix of category name and underscore '_'
.
Furthermore, an application may set public field AllowedMinimumShortCut to a value greater than 0
. In this case, the plug-in recognizes variables in CLI arguments already when at least this amount of characters is provided. In other words, when reading an argument as many characters of the variable name as possible are 'consumed' and if a minimum number is given with AllowedMinimumShortCut, such minimum is sufficient. If the remaining part of the argument string is either empty or continues with an equal sign '='
, then the variable is recognized (with an empty value or the value after the equal sign).
Fields AllowedMinimumShortCut and DefaultCategories may also be used in combination.
class detail::nextCLIArg (Used for implementation of iterator.)
Definition at line 320 of file config/plugins.hpp.
#include <plugins.hpp>
Public Field Index: | |
int | AllowedMinimumShortCut = 0 |
std::vector< AString > | AlternativeArgs |
std::vector< AString > | DefaultCategories |
Public Field Index: inherited from ConfigurationPlugin | |
XTernalizer * | StringConverter |
Public Method Index: | |
CLIArgs () | |
virtual | ~CLIArgs () override |
virtual ALIB_API Iterator * | GetIterator (const String §ionName) override |
virtual ALIB_API bool | Load (Variable &variable, bool searchOnly=false) override |
virtual ALIB_API String | Name () const override |
void | SetArgs (int argc, const void **argv=nullptr, bool areWideChar=false) |
Public Method Index: inherited from ConfigurationPlugin | |
virtual | ~ConfigurationPlugin () |
virtual bool | Store (Variable &variable) |
virtual bool | Store (Variable &variable, const String &externalizedValue) |
int AllowedMinimumShortCut = 0 |
If this field is set to a value greater than 0
, this plug-in recognizes variables in CLI arguments already when at least this amount of characters is provided. If the remaining part of the argument string is either empty or continues with an equal sign '='
, then the variable is recognized.
Definition at line 363 of file config/plugins.hpp.
std::vector<AString> AlternativeArgs |
If any value is added to this vector, its values are used as the source of command line arguments instead of using fields argCount and argVector.
This mechanic provides an alternative method to set the command line argument list.
Applications that have a dedicated (more sophisticated) CLI interface which performs more complex processing of CLI arguments, may collect any unrecognized CLI argument here to be duly recognized as a configuration variable instead
Definition at line 345 of file config/plugins.hpp.
|
protected |
The number of command line arguments.
Definition at line 328 of file config/plugins.hpp.
|
protected |
The list of command line arguments.
Definition at line 329 of file config/plugins.hpp.
std::vector<AString> DefaultCategories |
An application can specify one or more "default categories" by adding the category names here. Variables of these categories are recognized by the plug-in also when given without the prefix of category_
.
Definition at line 355 of file config/plugins.hpp.
|
protected |
Determines if argv is of type 'wchar **' or 'nchar **'
Definition at line 330 of file config/plugins.hpp.
|
inline |
Constructor. After creation, method SetArgs should be called to equip this instance with the command line arguments.
Definition at line 369 of file config/plugins.hpp.
|
inlineoverridevirtual |
Creates an iterator object to return all variables within a section.
The iterator object returned, needs to be deleted by the caller.
sectionName | The name of the section to iterate. |
Reimplemented from ConfigurationPlugin.
|
overridevirtual |
Searches the variable in the command line parameters.
variable | The variable to retrieve. |
searchOnly | If true , the variable is not set. Defaults to false . |
true
if variable was found, false
if not. Implements ConfigurationPlugin.
Definition at line 178 of file plugins.cpp.
|
overridevirtual |
Return the plug-in name, in this case, we read resource variable "CfgPlgCLI".
Implements ConfigurationPlugin.
Definition at line 173 of file plugins.cpp.
|
inline |
Sets the command line argument list. Needs to be called once after construction. Should not be invoked directly. Rather use method Configuration::SetCommandLineArgs .
argc | The number of arguments in argv |
argv | The list of command line arguments. |
areWideChar | If true , parameter argv is of type wchar_t ** ', otherwise of type char ** . Defaults to false . |
Definition at line 399 of file config/plugins.hpp.