Evo C++ Library v0.5.1
Public Member Functions | List of all members
CommandLineT< ConsoleT >::Command Struct Referenceabstract

#include <evo/commandline.h>

Detailed Description

template<class ConsoleT = Console>
struct evo::CommandLineT< ConsoleT >::Command

Used to set command options and arguments.

Public Member Functions

virtual ~Command ()
 Destructor. More...
 
virtual Optionadd (const String &str)=0
 Parse input string and add an option or argument as described to command. More...
 
virtual Optionaddarg (const String &key, const String &helpname, const String &help)=0
 Add a positional argument to command. More...
 
virtual Optionaddarg (const String &key, const String &help)=0
 Add a positional argument to command. More...
 
virtual void addflag (const String &names, const String &key, const String &help)=0
 Add an option flag to command. More...
 
virtual void addflag (const String &names, const String &help)=0
 Add an option flag to command. More...
 
virtual Optionaddopt (const String &names, const String &key, const String &helpname, const String &help)=0
 Add an option that stores a value to command. More...
 
virtual Optionaddopt (const String &names, const String &helpname, const String &help)=0
 Add an option that stores a value to command. More...
 
virtual Optionaddopt (const String &names, const String &help)=0
 Add an option that stores a value to command. More...
 
virtual void addsep ()=0
 Add an options separator in usage help. More...
 

Constructor & Destructor Documentation

◆ ~Command()

virtual ~Command ( )
inlinevirtual

Destructor.

Member Function Documentation

◆ add()

virtual Option& add ( const String str)
pure virtual

Parse input string and add an option or argument as described to command.

  • This calls addsep(), addflag(), addopt(), or addarg() depending on input
  • Use empty string to add an option separator
  • Option flag syntax: NAMES HELP
  • Option with value syntax: NAMES VALUE HELP
  • Argument syntax: NAME HELP
  • Where:
    • NAMES is a comma and/or space separated list of short or long option names (usually short first), the last of which is used as the option key (without dash or double dash prefix)
    • HELP is a help string for this option/argument (may contain newlines) – at least two spaces are required before this
    • VALUE is the name of the option value to show in usage help (also called helpname)
    • NAME is the argument name to show in usage help
Parameters
strInput string to parse

◆ addarg() [1/2]

virtual Option& addarg ( const String key,
const String helpname,
const String help 
)
pure virtual

Add a positional argument to command.

  • Multiple values for an argument are stored with a semicolon separator (i.e. they stack)
Parameters
keyKey to store option flag under when parsing arguments, example: outfile
helpnameName to represent argument value shown with usage help (usually in caps), example: OUTFILE
helpHelp string for this option to show with usage help, example: Output file to use
Returns
Option object for setting additonal argument information

◆ addarg() [2/2]

virtual Option& addarg ( const String key,
const String help 
)
pure virtual

Add a positional argument to command.

  • The key is also used as helpname
  • Multiple values for an argument are stored with a semicolon separator (i.e. they stack)
Parameters
keyKey to store option flag under when parsing arguments, example: outfile
helpHelp string for this option to show with usage help, example: Output file to use
Returns
Option object for setting additonal argument information

◆ addflag() [1/2]

virtual void addflag ( const String names,
const String key,
const String help 
)
pure virtual

Add an option flag to command.

  • When parsing repeated flags, the occurrences are counted and stored as a string value (if more than 1 occurrence)
  • Special option '-' (just a single dash) can be added here, this usually means read from stdin instead of a file
Parameters
namesOption names to look for when parsing arguments (comma separated)
keyKey to store option flag under when parsing arguments
helpHelp string for this option

◆ addflag() [2/2]

virtual void addflag ( const String names,
const String help 
)
pure virtual

Add an option flag to command.

  • The last name is used as the option key (without dash or double dash prefix)
  • When parsing repeated flags, the occurrences are counted and stored as a string value (if more than 1 occurrence)
  • Special option '-' (just a single dash) can be added here, this usually means read from stdin instead of a file
Parameters
namesOption names to look for when parsing arguments (comma separated)
helpHelp string for this option

◆ addopt() [1/3]

virtual Option& addopt ( const String names,
const String key,
const String helpname,
const String help 
)
pure virtual

Add an option that stores a value to command.

  • Multiple values allowed for the same option are stored with a semicolon separator
  • When parsing repeated options, previous values for that option are overwritten by default
Parameters
namesOption names to look for when parsing arguments (comma separated), example: -v,–verbose
keyKey to store option flag under when parsing arguments, example: outfile
helpnameName to represent option value shown with usage help (usually in caps), example: OUTFILE
helpHelp string for this option to show with usage help, example: Output file to use
Returns
Option object for setting additonal information

◆ addopt() [2/3]

virtual Option& addopt ( const String names,
const String helpname,
const String help 
)
pure virtual

Add an option that stores a value to command.

  • The last name is used as the option key (without dash or double dash prefix)
  • Multiple values allowed for the same option are stored with a semicolon separator
  • When parsing repeated options, previous values for that option are overwritten by default
Parameters
namesOption names to look for when parsing arguments (comma separated), example: -v,–verbose
helpnameName to represent option value shown with usage help (usually in caps), example: OUTFILE
helpHelp string for this option to show with usage help, example: Output file to use
Returns
Option object for setting additonal information

◆ addopt() [3/3]

virtual Option& addopt ( const String names,
const String help 
)
pure virtual

Add an option that stores a value to command.

  • The last name is used as both the option key and helpname (without dash or double dash prefix)
  • Multiple values allowed for the same option are stored with a semicolon separator
  • When parsing repeated options, previous values for that option are overwritten by default
Parameters
namesOption names to look for when parsing arguments (comma separated), example: -v,–verbose
helpHelp string for this option to show with usage help, example: Output file to use
Returns
Option object for setting additonal information

◆ addsep()

virtual void addsep ( )
pure virtual

Add an options separator in usage help.

  • This adds a blank line before the next option in usage help
  • This is useful for visually grouping related options in usage help

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