LibCppCmd v1.0 Beta 15
C++ Command Line Parsing Library
Loading...
Searching...
No Matches
Classes | Functions | Variables
CmdLine Namespace Reference

This namespace represents everthing related to command line parsing. More...

Classes

class  ArgParam
 A parameter populated by command line arguments (base class). More...
 
class  MultiPosParam
 A multi-value PosParam. More...
 
class  NameValuePair
 A pair of a name and a value. More...
 
class  Option
 An ArgParam that represents an Option. More...
 
class  OptionParam
 Provides parameters for ValueOption values. More...
 
class  Param
 A parameter that stores data from the command line (base class). More...
 
class  Parser
 Parses command line arguments. More...
 
class  PosParam
 A Positional command line ArgParam. More...
 
class  ProgParam
 A command line ArgParam populated by the program name. More...
 
class  ValueOption
 A command line Option that is populated with values. More...
 

Functions

std::string GenerateHelpLine (std::string name, std::string description)
 Generates a formatted line of help information.
 
bool IsNameValuePair (std::string pair)
 Determines if the specified string represents a NameValuePair.
 
bool IsOption (std::string arg)
 Determines if the specified argument represents an Option.
 
bool IsValidNonOptionName (std::string name)
 Checks the specified name to determine if it is valid.
 

Variables

const int helpIndentWidth
 The number of spaces to lefthand indent Param names in help.
 
const int helpNameFieldWidth
 The size the name field should be in help for alignment.
 
const int minNameSize
 Indicates the minimum size a valid Param name can be.
 
const int maxNameSize
 Indicates the maximum size a valid Param name can be.
 
const char optionalOpenBracket
 The open bracket used to show a Param is optional in help.
 
const char optionalCloseBracket
 The close bracket used to show a Param is optional in help.
 
const char mandatoryOpenBracket
 The open bracket used to show a Param is mandatory in help.
 
const char mandatoryCloseBracket
 The close bracket used to show a Param is mandatory in help.
 
const char * multiPosParamIndicator
 A string that indicates a Param is a MultiPosParam in help.
 
const char * unixOptionShortPrefix
 The short option prefix used with Option::Style::Unix.
 
const char * unixOptionLongPrefix
 The long option prefix used with Option::Style::Unix.
 
const char * windowsOptionShortPrefix
 The short option prefix used with Option::Style::Unix.
 
const char * windowsOptionLongPrefix
 The long option prefix used with Option::Style::Windows.
 
const char helpOptionShortName
 The short option name for the built-in help option.
 
const char * helpOptionLongName
 The long option name for the built-in help option.
 
const char * helpOptionDescription
 The description for the built-in help option.
 
const char * usageHeader
 The header indicating the Usage section of help.
 
const char * descriptionHeader
 The header indicating the Description section of help.
 
const char * posParamHeader
 The header indicating the Positional Parameters section of help.
 
const char * optionsHeader
 The header indicating the Options section of help.
 
const char * optionsLabel
 The label that indicates where Options go in the usage info.
 
const char * helpMessagePrefix
 The first part of the message indicating how to get help.
 
const char * helpMessagePostfix
 The second part of the message indicating how to get help.
 
const char * optionShortNameError
 An error message for invalid Option short names.
 
const char * optionLongNameError
 An error message for invalid Option long names.
 
const char * optionEmptyNameError
 An error message for empty Option names.
 
const char * emptyArgsError
 An error message for empty command line arguments.
 
const char * nameError
 An error message for invalid Parameter names.
 
const char * nullOptionError
 An error message for adding a null Option.
 
const char * nullOptionParamError
 An error message for adding a null OptionParam.
 
const char * nullPosParamError
 An error message for adding a null PosParam.
 
const char * nullProgParamError
 An error message for adding a null ProgParam.
 
const char * duplicateOptionError
 An error message for adding a duplicate Option.
 
const char * duplicatePosParamError
 An error message for adding a duplicate PosParam.
 
const char * duplicateOptionParamError
 An error message for adding a duplicate CommandLine::OptionParameter.
 

Detailed Description

This namespace represents everthing related to command line parsing.

The CmdLine namespace encapsulates all objects and functions related to command line argument parsing. Command line arguments are the string arguments passed to the main() function in the program from the OS, typically from a command line interfacte (CLI).

Function Documentation

◆ GenerateHelpLine()

std::string CmdLine::GenerateHelpLine ( std::string name,
std::string description )

Generates a formatted line of help information.

Accepts a Param name and description and indents both in a uniform way. This ensures each Param can have its name and description output in alignment with each other.

Parameters
nameThe name of the Param.
descriptionThe description of the Param.
Returns
The formatted help line.

◆ IsNameValuePair()

bool CmdLine::IsNameValuePair ( std::string pair)

Determines if the specified string represents a NameValuePair.

A valid NameValuePair is a non-empty string that, at a minimum, is comprised of a valid non-option name.

Parameters
pairThe string to evaluate.
Returns
True if the string is a name-value pair, otherwise false.

◆ IsOption()

bool CmdLine::IsOption ( std::string arg)

Determines if the specified argument represents an Option.

A command line argument represents an Option if it begins with a valid Option prefix and a valid Option name.

Parameters
argThe argument to evaluate.
Returns
True if the argument represents an Option, otherwise false.

◆ IsValidNonOptionName()

bool CmdLine::IsValidNonOptionName ( std::string name)

Checks the specified name to determine if it is valid.

A valid non-option name is one with the following invariants:

  1. Name must be non-empty.
  2. Name must contain only alpha numerics or - and _.
  3. Name must not be longer than 20 characters.
  4. Name must not start with an option prefix.
Parameters
nameThe name to evaluate.
Returns
True if the name is valid, otherwise false.