Logo ROOT  
Reference Guide
Loading...
Searching...
No Matches
ROOT::RCmdLineOpts Class Reference

Definition at line 99 of file optparse.hxx.

Classes

struct  RExpectedFlag
struct  RFlag
struct  RSettings

Public Types

enum  EFlagOpt { kFlagAllowMultiple = 1 << 0 , kFlagPrefixArg = 1 << 1 }
enum class  EFlagTreatment { kDefault , kSimple , kGrouped }
enum class  EFlagType { kSwitch , kWithArg }

Public Member Functions

 RCmdLineOpts (RSettings settings={EFlagTreatment::kDefault})
void AddFlag (std::initializer_list< std::string_view > aliases, EFlagType type=EFlagType::kSwitch, std::string_view help="", std::uint32_t flagOpts=0)
 Defines a new flag (either a switch or a flag with argument).
const std::vector< std::string > & GetArgs () const
 Retrieves all positional arguments.
const std::vector< std::string > & GetErrors () const
 Returns all parsing errors.
const std::vector< RFlag > & GetFlags () const
 Retrieves all parsed flags.
std::string_view GetFlagValue (std::string_view name) const
 If name refers to a previously-defined non-switch flag, gets its value.
template<typename T>
std::optional< T > GetFlagValueAs (std::string_view name) const
std::vector< std::string_view > GetFlagValues (std::string_view name) const
 If name refers to a previously-defined non-switch flag, gets its values.
template<typename T>
std::vector< T > GetFlagValuesAs (std::string_view name) const
int GetSwitch (std::string_view name) const
 If name refers to a previously-defined switch (i.e.
void Parse (const char **args, std::size_t nArgs)
bool ReportErrors (std::ostream &stream=std::cerr) const
 Conveniency method to print any errors to stream.

Private Member Functions

const RExpectedFlagGetExpectedFlag (std::string_view name) const

Private Attributes

std::vector< std::string > fArgs
std::vector< std::string > fErrors
std::vector< RExpectedFlagfExpectedFlags
std::vector< RFlagfFlags
RSettings fSettings

#include </home/stephan/code/root-2/main/src/optparse.hxx>

Member Enumeration Documentation

◆ EFlagOpt

Enumerator
kFlagAllowMultiple 1 << 0 

Flag is allowed to appear multiple times (default: it's an error to see the same flag twice).

kFlagPrefixArg 1 << 1 

Flag argument can appear right after this flag without a space or equal sign in between.

Note that marking any short flag with this disables flag grouping!

Definition at line 129 of file optparse.hxx.

◆ EFlagTreatment

Enumerator
kDefault 

Will result to kGrouped if you don't define any short flag longer than 1 character, otherwise kSimple.

kSimple 

-abc will always be treated as the single flag "-abc"

kGrouped 

-abc will be treated as "-a -b -c".

This is only valid for short flags. With this setting you cannot define short flags that are more than 1 character long nor ones that are marked with kFlagPrefixArg.

Definition at line 101 of file optparse.hxx.

◆ EFlagType

enum class ROOT::RCmdLineOpts::EFlagType
strong
Enumerator
kSwitch 
kWithArg 

Definition at line 117 of file optparse.hxx.

Constructor & Destructor Documentation

◆ RCmdLineOpts()

ROOT::RCmdLineOpts::RCmdLineOpts ( RSettings settings = {EFlagTreatment::kDefault})
inlineexplicit

Definition at line 177 of file optparse.hxx.

Member Function Documentation

◆ AddFlag()

void ROOT::RCmdLineOpts::AddFlag ( std::initializer_list< std::string_view > aliases,
EFlagType type = EFlagType::kSwitch,
std::string_view help = "",
std::uint32_t flagOpts = 0 )
inline

Defines a new flag (either a switch or a flag with argument).

The flag may be referred to as any of the values inside aliases (e.g. { "-h", "--help" }). You must pass at least 1 string inside aliases. All strings inside aliases must start with - or -- and be at least 1 character long (aside the dashes). Flags starting with a single - are considered "short", regardless of their actual length. If all short flags are 1 character long, they may be collapsed into one and parsed as individual flags (meaning a string like "-fgk" will be parsed as "-f -g -k") and the final flag may have a following argument. This does NOT happen if any short flag is longer than 1 character, to avoid ambiguity.

Parameters
aliasesAll the equivalent names of this flag
typeWhat kind of flag is this: with arguments or not
helpHelp string for the flag
flagOptsBitmask of EFlagOpt for additional options

Definition at line 208 of file optparse.hxx.

◆ GetArgs()

const std::vector< std::string > & ROOT::RCmdLineOpts::GetArgs ( ) const
inline

Retrieves all positional arguments.

Definition at line 182 of file optparse.hxx.

◆ GetErrors()

const std::vector< std::string > & ROOT::RCmdLineOpts::GetErrors ( ) const
inline

Returns all parsing errors.

Definition at line 180 of file optparse.hxx.

◆ GetExpectedFlag()

const RExpectedFlag * ROOT::RCmdLineOpts::GetExpectedFlag ( std::string_view name) const
inlineprivate

Definition at line 156 of file optparse.hxx.

◆ GetFlags()

const std::vector< RFlag > & ROOT::RCmdLineOpts::GetFlags ( ) const
inline

Retrieves all parsed flags.

Definition at line 184 of file optparse.hxx.

◆ GetFlagValue()

std::string_view ROOT::RCmdLineOpts::GetFlagValue ( std::string_view name) const
inline

If name refers to a previously-defined non-switch flag, gets its value.

Exceptions
std::invalid_argumentif the flag was undefined or defined as a switch flag

Definition at line 321 of file optparse.hxx.

◆ GetFlagValueAs()

template<typename T>
std::optional< T > ROOT::RCmdLineOpts::GetFlagValueAs ( std::string_view name) const
inline

Definition at line 356 of file optparse.hxx.

◆ GetFlagValues()

std::vector< std::string_view > ROOT::RCmdLineOpts::GetFlagValues ( std::string_view name) const
inline

If name refers to a previously-defined non-switch flag, gets its values.

This will never return more than 1 value unless the flag is allowed to appear multiple times.

Exceptions
std::invalid_argumentif the flag was undefined or defined as a switch flag

Definition at line 330 of file optparse.hxx.

◆ GetFlagValuesAs()

template<typename T>
std::vector< T > ROOT::RCmdLineOpts::GetFlagValuesAs ( std::string_view name) const
inline

Definition at line 367 of file optparse.hxx.

◆ GetSwitch()

int ROOT::RCmdLineOpts::GetSwitch ( std::string_view name) const
inline

If name refers to a previously-defined switch (i.e.

a boolean flag), returns how many times the flag appeared (this will never be more than 1 unless the flag is allowed to appear multiple times).

Exceptions
std::invalid_argumentif the flag was undefined or defined as a flag with arguments

Definition at line 300 of file optparse.hxx.

◆ Parse()

void ROOT::RCmdLineOpts::Parse ( const char ** args,
std::size_t nArgs )
inline

Definition at line 425 of file optparse.hxx.

◆ ReportErrors()

bool ROOT::RCmdLineOpts::ReportErrors ( std::ostream & stream = std::cerr) const
inline

Conveniency method to print any errors to stream.

Returns
true if any error was printed

Definition at line 188 of file optparse.hxx.

Member Data Documentation

◆ fArgs

std::vector<std::string> ROOT::RCmdLineOpts::fArgs
private

Definition at line 140 of file optparse.hxx.

◆ fErrors

std::vector<std::string> ROOT::RCmdLineOpts::fErrors
private

Definition at line 154 of file optparse.hxx.

◆ fExpectedFlags

std::vector<RExpectedFlag> ROOT::RCmdLineOpts::fExpectedFlags
private

Definition at line 153 of file optparse.hxx.

◆ fFlags

std::vector<RFlag> ROOT::RCmdLineOpts::fFlags
private

Definition at line 139 of file optparse.hxx.

◆ fSettings

RSettings ROOT::RCmdLineOpts::fSettings
private

Definition at line 138 of file optparse.hxx.

Collaboration diagram for ROOT::RCmdLineOpts:
[legend]

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