Fancy argparser
Single file argument parser for c++
Loading...
Searching...
No Matches
ARGPARSE_NAMESPACE_NAME Namespace Reference

namespace of argument parser constants and Classes can be changed if ARGPARSE_NAMESPACE_NAME macro specified during compilation. More...

Classes

class  Argument
 This class represents argument configuration which should be passed to ArgumentParser objects instance. More...
struct  NamedArgSpec
 Aggregate description of a named argument, for keyword-style construction. More...
struct  PositionalArgSpec
 Aggregate description of a positional argument, for keyword-style construction with C++20 designated initializers. More...
class  ArgumentParsed
 Class which represent actual parsed argument in case of successfully parsing. More...
class  ArgumentsObject
 Class that carries result of real parsing Indicates if parsing is successful and allows to get ArgumentParsed object in that case. More...
class  ArgumentParser
 Main class of argument parser hold all user arguments from code and orchestrate other classes in order to parse command line input. More...

Enumerations

enum class  ArgTypeCast : int {
  e_String , e_int , e_longlong , e_double ,
  e_bool
}
 Supported types for argument If needed type is not in this list, then just use e_String. More...

Functions

Argument CreateNamedArgument (const std::string &shortName="", const std::string &longName="", const int argsCount=1, ArgTypeCast argType=ArgTypeCast::e_String, const bool required=true, const std::string &help="")
 Helper function to create named argument.
Argument CreatePositionalArgument (const std::string &positionalName="", const int argsCount=1, ArgTypeCast argType=ArgTypeCast::e_String, const bool required=true, const std::string &help="")
 Helper function to create positional argument.
Argument CreateNamedArgument (const NamedArgSpec &spec)
 Keyword-style factory for a named argument.
Argument CreatePositionalArgument (const PositionalArgSpec &spec)
 Keyword-style factory for a positional argument.

Variables

const int kAnyArgCount = -1
 constant to indicate arguments with various count from 0 to infinite
const int kFromOneToInfiniteArgCount = -2
 constant to indicate arguments with various count from 1 to infinite

Detailed Description

namespace of argument parser constants and Classes can be changed if ARGPARSE_NAMESPACE_NAME macro specified during compilation.

By default is namespace name is "argparse"

Enumeration Type Documentation

◆ ArgTypeCast

enum class ARGPARSE_NAMESPACE_NAME::ArgTypeCast : int
strong

Supported types for argument If needed type is not in this list, then just use e_String.

Enumerator
e_String 
e_int 
e_longlong 
e_double 
e_bool 

Definition at line 103 of file argparse.h.

Function Documentation

◆ CreateNamedArgument() [1/2]

Argument ARGPARSE_NAMESPACE_NAME::CreateNamedArgument ( const NamedArgSpec & spec)
inline

Keyword-style factory for a named argument.

See NamedArgSpec.

Parameters
specaggregate of the argument's properties
Returns
instance of Argument

Definition at line 621 of file argparse.h.

◆ CreateNamedArgument() [2/2]

Argument ARGPARSE_NAMESPACE_NAME::CreateNamedArgument ( const std::string & shortName = "",
const std::string & longName = "",
const int argsCount = 1,
ArgTypeCast argType = ArgTypeCast::e_String,
const bool required = true,
const std::string & help = "" )
inline

Helper function to create named argument.

Parameters
shortNameShort name if needed. Will be used with single prefix. Short name could be auto-generated if possible when m_allowAbbrev in ArgumentParsed set to true)
longNameFull name of argument
argsCountCount of arguments (use kFromOneToInfiniteArgCount or kAnyArgCount for various arguments count)
argTypee_String, e_int, e_longlong, e_double, e_bool
requiredMarker if argument should be passed or ignored if missed.
helpInitial part of help for current argument in case of auto-generated help.
Returns
instance of Argument
Note
inline: this is a free function in a header, so it must have inline linkage to be safely included in more than one translation unit.

Definition at line 568 of file argparse.h.

◆ CreatePositionalArgument() [1/2]

Argument ARGPARSE_NAMESPACE_NAME::CreatePositionalArgument ( const PositionalArgSpec & spec)
inline

Keyword-style factory for a positional argument.

See PositionalArgSpec.

Parameters
specaggregate of the argument's properties
Returns
instance of Argument

Definition at line 641 of file argparse.h.

◆ CreatePositionalArgument() [2/2]

Argument ARGPARSE_NAMESPACE_NAME::CreatePositionalArgument ( const std::string & positionalName = "",
const int argsCount = 1,
ArgTypeCast argType = ArgTypeCast::e_String,
const bool required = true,
const std::string & help = "" )
inline

Helper function to create positional argument.

Parameters
positionalNameName of positional argument to access from code.
argsCountCount of arguments (use kFromOneToInfiniteArgCount or kAnyArgCount for various arguments count)
argTypee_String, e_int, e_longlong, e_double, e_bool
requiredMarker if argument should be passed or ignored if missed.
helpInitial part of help for current argument in case of auto-generated help.
Returns
instance of Argument
Note
inline: see CreateNamedArgument – required for multi-TU inclusion.

Definition at line 587 of file argparse.h.

Variable Documentation

◆ kAnyArgCount

const int ARGPARSE_NAMESPACE_NAME::kAnyArgCount = -1

constant to indicate arguments with various count from 0 to infinite

Definition at line 114 of file argparse.h.

◆ kFromOneToInfiniteArgCount

const int ARGPARSE_NAMESPACE_NAME::kFromOneToInfiniteArgCount = -2

constant to indicate arguments with various count from 1 to infinite

Definition at line 117 of file argparse.h.