XII Release 0.1.0
Loading...
Searching...
No Matches
xiiCommandLineOption Class Referenceabstract

xiiCommandLineOption (and derived types) are used to define options that the application supports. More...

#include <CommandLineOptions.h>

Inheritance diagram for xiiCommandLineOption:
[legend]

Public Types

enum class  LogAvailableModes { Always , IfHelpRequested }
 
enum class  LogMode {
  Never , FirstTime , FirstTimeIfSpecified , Always ,
  AlwaysIfSpecified
}
 Describes whether the value of an option (and whether something went wrong), should be printed to xiiLog. More...
 

Public Member Functions

 xiiCommandLineOption (xiiStringView sSortingGroup)
 
virtual void GetSortingGroup (xiiStringBuilder &ref_sOut) const
 Writes the sorting group name to 'out'.
 
virtual void GetOptions (xiiStringBuilder &ref_sOut) const =0
 Writes all the supported options (e.g. '-arg') to 'out'. If more than one option is allowed, they should be separated with semicolons or pipes.
 
void GetSplitOptions (xiiStringBuilder &out_sAll, xiiDynamicArray< xiiStringView > &ref_splitOptions) const
 Returns the supported option names (e.g. '-arg') as split strings.
 
virtual void GetParamShortDesc (xiiStringBuilder &ref_sOut) const =0
 Returns a very short description of the option (type). For example "<int>" or "<enum>".
 
virtual void GetParamDefaultValueDesc (xiiStringBuilder &ref_sOut) const =0
 Returns a very short string for the options default value. For example "0" or "auto".
 
virtual void GetLongDesc (xiiStringBuilder &ref_sOut) const =0
 Returns a proper description of the option.
 
virtual xiiStringView GetType ()=0
 Returns a string indicating the exact implementation type.
 

Static Public Member Functions

static bool IsHelpRequested (const xiiCommandLineUtils *pUtils=xiiCommandLineUtils::GetGlobalInstance())
 Checks whether a command line was passed that requests help output.
 
static xiiResult RequireOptions (xiiStringView sRequiredOptions, xiiString *pMissingOption=nullptr, const xiiCommandLineUtils *pUtils=xiiCommandLineUtils::GetGlobalInstance())
 Checks whether all required options are passed to the command line.
 
static bool LogAvailableOptions (LogAvailableModes mode, xiiStringView sGroupFilter={}, const xiiCommandLineUtils *pUtils=xiiCommandLineUtils::GetGlobalInstance())
 Prints all available options to the xiiLog.
 
static bool LogAvailableOptionsToBuffer (xiiStringBuilder &out_sBuffer, LogAvailableModes mode, xiiStringView sGroupFilter={}, const xiiCommandLineUtils *pUtils=xiiCommandLineUtils::GetGlobalInstance())
 Same as LogAvailableOptions() but captures the output from xiiLog and returns it in a xiiStringBuilder.
 
- Static Public Member Functions inherited from xiiNoBase
static const xiiRTTIGetStaticRTTI ()
 

Protected Attributes

xiiStringView m_sSortingGroup
 
- Protected Attributes inherited from xiiEnumerable< xiiCommandLineOption >
xiiEnumerablem_pNextInstance
 

Detailed Description

xiiCommandLineOption (and derived types) are used to define options that the application supports.

Command line options are created as global variables anywhere throughout the code, wherever they are needed. The point of using them over going through xiiCommandLineUtils directly, is that the options can be listed automatically and thus an application can print all available options, when the user requests help.

Consequently, their main purpose is to make options discoverable and to document them in a consistent manner.

Additionally, classes like xiiCommandLineOptionEnum add functionality that makes some options easier to setup.

Member Enumeration Documentation

◆ LogAvailableModes

Enumerator
Always 

Logs the available modes no matter what.

IfHelpRequested 

Only logs the modes, if '-h', '-help', '-?' or something similar was specified.

◆ LogMode

enum class xiiCommandLineOption::LogMode
strong

Describes whether the value of an option (and whether something went wrong), should be printed to xiiLog.

Enumerator
Never 

Don't log anything.

FirstTime 

Only print the information the first time a value is accessed.

FirstTimeIfSpecified 

Only on first access and only if the user specified the value on the command line.

Always 

Always log the options value on access.

AlwaysIfSpecified 

Always log values, if the user specified non-default ones.

Constructor & Destructor Documentation

◆ xiiCommandLineOption()

xiiCommandLineOption::xiiCommandLineOption ( xiiStringView sSortingGroup)
inline
Parameters
sSortingGroupThis string is used to sort options. Application options should start with an underscore, such that they appear first in the output.

Member Function Documentation

◆ GetLongDesc()

virtual void xiiCommandLineOption::GetLongDesc ( xiiStringBuilder & ref_sOut) const
pure virtual

Returns a proper description of the option.

The long description is allowed to contain newlines (
) and the output will be formatted accordingly.

Implemented in xiiCommandLineOptionDoc.

◆ GetOptions()

virtual void xiiCommandLineOption::GetOptions ( xiiStringBuilder & ref_sOut) const
pure virtual

Writes all the supported options (e.g. '-arg') to 'out'. If more than one option is allowed, they should be separated with semicolons or pipes.

Implemented in xiiCommandLineOptionDoc.

◆ GetParamDefaultValueDesc()

virtual void xiiCommandLineOption::GetParamDefaultValueDesc ( xiiStringBuilder & ref_sOut) const
pure virtual

Returns a very short string for the options default value. For example "0" or "auto".

Implemented in xiiCommandLineOptionDoc, xiiCommandLineOptionEnum, xiiCommandLineOptionFloat, and xiiCommandLineOptionInt.

◆ GetParamShortDesc()

virtual void xiiCommandLineOption::GetParamShortDesc ( xiiStringBuilder & ref_sOut) const
pure virtual

Returns a very short description of the option (type). For example "<int>" or "<enum>".

Implemented in xiiCommandLineOptionDoc, xiiCommandLineOptionEnum, xiiCommandLineOptionFloat, and xiiCommandLineOptionInt.

◆ GetType()

virtual xiiStringView xiiCommandLineOption::GetType ( )
pure virtual

◆ LogAvailableOptions()

bool xiiCommandLineOption::LogAvailableOptions ( LogAvailableModes mode,
xiiStringView sGroupFilter = {},
const xiiCommandLineUtils * pUtils = xiiCommandLineUtils::GetGlobalInstance() )
static

Prints all available options to the xiiLog.

Parameters
sGroupFilterIf this is empty, all options from all 'sorting groups' are logged. If non-empty, only options from sorting groups that appear in this string will be logged.

◆ RequireOptions()

xiiResult xiiCommandLineOption::RequireOptions ( xiiStringView sRequiredOptions,
xiiString * pMissingOption = nullptr,
const xiiCommandLineUtils * pUtils = xiiCommandLineUtils::GetGlobalInstance() )
static

Checks whether all required options are passed to the command line.

The options are passed as a semicolon-separated list (spare spaces are stripped away), for instance "-opt1; -opt2"


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