sptk2 logo
SPTK Home Page
Classes | Public Member Functions | Static Public Member Functions | List of all members
sptk::CommandLine Class Reference

#include <CommandLine.h>

Classes

class  CommandLineArgument
 
class  CommandLineElement
 
class  CommandLineOption
 
class  CommandLineParameter
 
class  Visibility
 

Public Member Functions

void printCommands (const String &onlyForCommand, size_t screenColumns, size_t nameColumns, const Strings &sortedCommands, size_t helpTextColumns) const
 
void printOptions (const String &onlyForCommand, size_t screenColumns, size_t nameColumns, const Strings &sortedOptions, size_t helpTextColumns) const
 
 CommandLine (const String &programVersion, const String &description, const String &commandLinePrototype)
 
void defineOption (const String &fullName, const String &shortName, const Visibility &useForCommands, const String &help)
 
void defineParameter (const String &fullName, const String &shortName, const String &valueName, const String &validateValue, const Visibility &useForCommands, const String &defaultValue, const String &help)
 
void defineArgument (const String &fullName, const String &helpText)
 
void init (size_t argc, const char **argv)
 
String getOptionValue (const String &name) const
 
bool hasOption (const String &name) const
 
void setOptionValue (const String &name, const String &value="yes")
 
const Stringsarguments () const
 
void printHelp (size_t screenColumns) const
 
void printHelp (const String &onlyForCommand, size_t screenColumns) const
 
void printVersion () const
 

Static Public Member Functions

static void printLine (const String &ch, size_t count)
 
static Strings preprocessArguments (const std::vector< const char * > &argv)
 
static Strings rewriteArguments (const Strings &arguments)
 

Detailed Description

Command line parser

Constructor & Destructor Documentation

◆ CommandLine()

sptk::CommandLine::CommandLine ( const String programVersion,
const String description,
const String commandLinePrototype 
)

Constructor

Parameters
programVersionProgram version and copyright message (forhelp only).
descriptionProgram description (forhelp only).
commandLinePrototypeCommand line prototype (forhelp only).

Member Function Documentation

◆ arguments()

const Strings & sptk::CommandLine::arguments ( ) const

Returns list of command line arguments

◆ defineArgument()

void sptk::CommandLine::defineArgument ( const String fullName,
const String helpText 
)

Defines command line argument/command.

Parameters
fullNameArgument/command name
helpTextHelp (description) for the element

◆ defineOption()

void sptk::CommandLine::defineOption ( const String fullName,
const String shortName,
const Visibility useForCommands,
const String help 
)

Defines command line option

An option doesn't expect a value. If it is present in command line, it assumes value 'yes'. Otherwise it has value 'no'.

Parameters
fullNameElement name
shortNameShort element name (single character, options only)
useForCommandsElement visibility for a command (options only)
helpHelp (description) for the element

◆ defineParameter()

void sptk::CommandLine::defineParameter ( const String fullName,
const String shortName,
const String valueName,
const String validateValue,
const Visibility useForCommands,
const String defaultValue,
const String help 
)

Defines command line parameter

Parameters
fullNameElement name
shortNameShort element name (single character, options only)
valueNameValue name
validateValueValue validation regular expression
useForCommandsElement visibility for a command (options only)
defaultValueOption default value
helpHelp (description) for the element

◆ getOptionValue()

String sptk::CommandLine::getOptionValue ( const String name) const

Returns actual option value

Parameters
nameOption name

◆ hasOption()

bool sptk::CommandLine::hasOption ( const String name) const

Returns true if actual command line contains option

Parameters
nameOption name

◆ init()

void sptk::CommandLine::init ( size_t  argc,
const char **  argv 
)

Parses actual command line arguments.

Should be executed after any define* methods of this class.

Parameters
argcNumber of command line arguments (from main(argc,argv)).
argvCommand line arguments (from main(argc,argv)).

◆ preprocessArguments()

static Strings sptk::CommandLine::preprocessArguments ( const std::vector< const char * > &  argv)
static

Preprocess command line arguments

Parameters
argcNumber of command line arguments
argvCommand line arguments
Returns
preprocessed command line arguments

◆ printCommands()

void sptk::CommandLine::printCommands ( const String onlyForCommand,
size_t  screenColumns,
size_t  nameColumns,
const Strings sortedCommands,
size_t  helpTextColumns 
) const

Print help on commands

Parameters
onlyForCommandOptional: if not empty then print only this command help
screenColumnsScreen width in columns
nameColumnsNumber of columns for command names
sortedCommandsSorted command list
helpTextColumnsNumber of columns for help text

◆ printHelp() [1/2]

void sptk::CommandLine::printHelp ( const String onlyForCommand,
size_t  screenColumns 
) const

Prints help for a given command/argument

Parameters
onlyForCommandCommand to print help for
screenColumnsScreen width in columns

◆ printHelp() [2/2]

void sptk::CommandLine::printHelp ( size_t  screenColumns) const

Prints full help

Parameters
screenColumnsScreen width in columns

◆ printLine()

static void sptk::CommandLine::printLine ( const String ch,
size_t  count 
)
static

prints a line of characters

Parameters
chCharacter to print
countNumber of characters to print

◆ printOptions()

void sptk::CommandLine::printOptions ( const String onlyForCommand,
size_t  screenColumns,
size_t  nameColumns,
const Strings sortedOptions,
size_t  helpTextColumns 
) const

Print help on options

Parameters
onlyForCommandOptional: if not empty then print only this command help
screenColumnsScreen width in columns
nameColumnsNumber of columns for option names
sortedOptionsSorted option list
helpTextColumnsNumber of columns for help text

◆ printVersion()

void sptk::CommandLine::printVersion ( ) const

Prints program version

◆ rewriteArguments()

static Strings sptk::CommandLine::rewriteArguments ( const Strings arguments)
static

Re-write command line arguments

Parameters
argumentsCommand line arguments
Returns
re-written command line arguments

◆ setOptionValue()

void sptk::CommandLine::setOptionValue ( const String name,
const String value = "yes" 
)

Re-defines actual option value

Parameters
nameOption name
valueOption value

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

Fri Oct 14 2022 09:58:38: SPTK 5.4.1