ALib C++ Framework
by
Library Version: 2511 R0
Documentation generated by doxygen
Loading...
Searching...
No Matches
alib::cli::Option Struct Reference

Description:

An option of a command-line. Options are read "automatically" using their declaration information defined with externalized strings (resources) accessed through ALib Enum Records associated with enum elements of enum custom types.

However, such automatic read is limited due to the fact, that the simple values and flags defined with OptionDecl, cannot provide the flexibility needed to perfectly parse options with a complex syntax.

In this case, the way out is to use custom code that invokes ReadOptions and then processes all options that may have remaining arguments left in the list. By using the inherited field Position, further arguments may be consumed from ArgsLeft.
Note that the term "processing all options" may mean a nested loop. The outer is over the option types in the field Options, the inner is over the vector of options per type.

Definition at line 349 of file arguments.inl.

Inheritance diagram for alib::cli::Option:
alib::cli::Parsed

Public Field Index:

ListMA< String, Recycling::Shared > Args
 Arguments belonging to this option.
OptionDeclDeclaration = nullptr
 The declaration struct.
Public Field Index: inherited from alib::cli::Parsed
CommandLineCmdLine
 The cli command-line.
integer ConsumedArguments
integer Position

Public Method Index:

 Option (CommandLine *cmdLine)
bool Read (OptionDecl &decl, String &arg, const integer argNo)
Public Method Index: inherited from alib::cli::Parsed
 Parsed (CommandLine *cmdLine)

Field Details:

◆ Args

ListMA<String, Recycling::Shared> alib::cli::Option::Args

Arguments belonging to this option.

Definition at line 355 of file arguments.inl.

◆ Declaration

OptionDecl* alib::cli::Option::Declaration = nullptr

The declaration struct.

Definition at line 352 of file arguments.inl.

Constructor(s) / Destructor Details:

◆ Option()

alib::cli::Option::Option ( CommandLine * cmdLine)
inline

Constructor

Parameters
cmdLineThe command-line main object.

Definition at line 508 of file commandline.inl.

Method Details:

◆ Read()

bool alib::cli::Option::Read ( OptionDecl & decl,
String & arg,
const integer argNo )

Tries to read the object from the current CLI arg(s).

Note
Unlike the read methods bool Read(CommandDecl&)  and bool Read(ParameterDecl&) , this method expects the argument to test not only by number with argNo but as well with string parameter arg.
This redundancy is needed to easily implement shortcut options, that just replace a shortcut option read to another one, probably with a preset argument included.
Parameters
declThe declaration used for reading.
argThe argument string starting with one or two hyphens.
argNoThe position of reading.
Returns
The true on success, false otherwise.

Definition at line 64 of file arguments.cpp.


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