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

#include <CommandLine.h>

Inheritance diagram for sptk::CommandLine::CommandLineElement:
sptk::CommandLine::CommandLineArgument sptk::CommandLine::CommandLineOption sptk::CommandLine::CommandLineParameter

Public Types

enum class  Type { IS_UNKNOWN , IS_COMMAND , IS_OPTION , IS_VALUE_OPTION }
 

Public Member Functions

 CommandLineElement (const String &name, const String &shortName, const String &help, const Visibility &useWithCommands)
 
virtual ~CommandLineElement ()=default
 
virtual Type type () const
 
virtual String name () const
 
virtual String shortName () const
 
virtual bool hasValue () const
 
virtual void validate (const String &value) const
 
virtual String printableName () const
 
bool useWithCommand (const String &command) const
 
void formatHelp (size_t textWidth, Strings &formattedText) const
 
void printHelp (size_t nameWidth, size_t textWidth, const String &optionDefaultValue) const
 

Detailed Description

Command line element that could be argument/command, option, or option with value

Member Enumeration Documentation

◆ Type

Command line element type

Enumerator
IS_UNKNOWN 

Type is unknown or undefined.

IS_COMMAND 

Element is a command, not starting from '-' character.

IS_OPTION 

Element is an option that doesn't expect value.

IS_VALUE_OPTION 

Element is an option that expects value.

Constructor & Destructor Documentation

◆ CommandLineElement()

sptk::CommandLine::CommandLineElement::CommandLineElement ( const String name,
const String shortName,
const String help,
const Visibility useWithCommands 
)

Constructor

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

◆ ~CommandLineElement()

virtual sptk::CommandLine::CommandLineElement::~CommandLineElement ( )
virtualdefault

Destructor

Member Function Documentation

◆ formatHelp()

void sptk::CommandLine::CommandLineElement::formatHelp ( size_t  textWidth,
Strings formattedText 
) const

Formats element help for printout

Parameters
textWidthHelp text width
formattedTextFormatted help text

◆ hasValue()

virtual bool sptk::CommandLine::CommandLineElement::hasValue ( ) const
virtual

Returns true if element expects value

Reimplemented in sptk::CommandLine::CommandLineOption, and sptk::CommandLine::CommandLineParameter.

◆ name()

virtual String sptk::CommandLine::CommandLineElement::name ( ) const
virtual

Returns element name

◆ printableName()

virtual String sptk::CommandLine::CommandLineElement::printableName ( ) const
virtual

Returns element name in help print format

Reimplemented in sptk::CommandLine::CommandLineOption, and sptk::CommandLine::CommandLineParameter.

◆ printHelp()

void sptk::CommandLine::CommandLineElement::printHelp ( size_t  nameWidth,
size_t  textWidth,
const String optionDefaultValue 
) const

Prints element help

Parameters
nameWidthOptional name width
textWidthHelp text width
optionDefaultValueOption default value (if any)
outputOptinal output stream

◆ shortName()

virtual String sptk::CommandLine::CommandLineElement::shortName ( ) const
virtual

Returns element short name

◆ type()

virtual Type sptk::CommandLine::CommandLineElement::type ( ) const
virtual

◆ useWithCommand()

bool sptk::CommandLine::CommandLineElement::useWithCommand ( const String command) const

Returns true if element may be used with command (options only)

◆ validate()

virtual void sptk::CommandLine::CommandLineElement::validate ( const String value) const
virtual

Validates given value (for elements that provide validation)

Throws an exception if the value is invalid

Parameters
valueValue to validate

Reimplemented in sptk::CommandLine::CommandLineParameter.


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

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