Euphoria
eu::core::argparse Namespace Reference

Classes

struct  FileOutput
 option where the output can either be a single file or "infinite" More...
 
struct  ParseResult
 
struct  NameAndArguments
 container for arguments passed to main More...
 
struct  ArgumentReader
 "file" like api for reading arguments More...
 
struct  Printer
 generic output class More...
 
struct  ConsolePrinter
 console output More...
 
struct  Runner
 shared data between parsing functions More...
 
struct  Name
 represents a command line argument optional: More...
 
struct  Argument
 base class for argument More...
 
struct  ArgumentAndName
 named tuple class for argument and name More...
 
struct  ArgumentNoValue
 a argument with no value, probably either a –set-true or a void function like –help More...
 
struct  SingleArgument
 a single argument, probably either a –count 3 or positional input More...
 
struct  MultiArgument
 a single argument, probably either a –count 3 or positional input More...
 
struct  SubParserNames
 valid names for a single subparser example: [checkout, co] or [pull] More...
 
struct  SubParserContainer
 data about a subparser More...
 
struct  SubParserGroup
 subparsers can be grouped and this structs represents that group More...
 
struct  ParserBase
 base for the parser, start with Parser and add one or more subparsers More...
 
struct  SubParser
 subparser, don't create manually but add to a existing parser AddSubParsers()->Add(...); More...
 
struct  Parser
 root parser. start argumentparsing with this one More...
 

Typedefs

template<typename T >
using ParseFunction = std::function< Result< T >(const std::string &value)>
 generic parse function More...
 
using SubParserCallback = std::function< ParseResult(SubParser *)>
 
using CompleteFunction = std::function< ParseResult()>
 

Enumerations

enum class  State { adding , parsing }
 enum to catch adding arguments during parsing in a callback More...
 
enum class  SubParserStyle { greedy , fallback , inherit }
 how the subparsing is handled, non-greedy are useful for 'scripting' with subparsers More...
 

Functions

std::string to_string (const ParseResult &pr)
 
bool operator== (const ParseResult &lhs, const ParseResult &rhs)
 
bool operator!= (const ParseResult &lhs, const ParseResult &rhs)
 
std::string to_string (const eu::core::argparse::NameAndArguments &args)
 
void print_parse_error (Runner *runner, ParserBase *base, const std::string &error_message)
 
std::string create_default_nargs (const Name &name)
 
int parse_from_main (Parser *parser, int argc, char *argv[])
 helper function for parsing directly from main More...
 

Variables

constexpr ParseResult error = ParseResult{ ParseResult::Type::error }
 no error occurred More...
 
constexpr ParseResult ok = ParseResult{ ParseResult::Type::ok }
 all ok More...
 
constexpr ParseResult quit = ParseResult{ ParseResult::Type::quit }
 all ok, but quit requested More...
 

Typedef Documentation

◆ CompleteFunction

using eu::core::argparse::CompleteFunction = typedef std::function<ParseResult ()>

Definition at line 343 of file argparse.h.

◆ ParseFunction

template<typename T >
using eu::core::argparse::ParseFunction = typedef std::function<Result<T> (const std::string& value)>

generic parse function

Definition at line 338 of file argparse.h.

◆ SubParserCallback

using eu::core::argparse::SubParserCallback = typedef std::function<ParseResult (SubParser*)>

Definition at line 342 of file argparse.h.

Enumeration Type Documentation

◆ State

enum to catch adding arguments during parsing in a callback

Enumerator
adding 
parsing 

Definition at line 22 of file argparse.h.

◆ SubParserStyle

how the subparsing is handled, non-greedy are useful for 'scripting' with subparsers

Enumerator
greedy 

parse all arguments

fallback 

if argument is invalid, go back one step and try there

inherit 

inherit from parent

Definition at line 398 of file argparse.h.

Function Documentation

◆ create_default_nargs()

std::string eu::core::argparse::create_default_nargs ( const Name name)

Definition at line 794 of file argparse.cc.

◆ operator!=()

bool eu::core::argparse::operator!= ( const ParseResult lhs,
const ParseResult rhs 
)

Definition at line 116 of file argparse.cc.

◆ operator==()

bool eu::core::argparse::operator== ( const ParseResult lhs,
const ParseResult rhs 
)

Definition at line 109 of file argparse.cc.

◆ parse_from_main()

int eu::core::argparse::parse_from_main ( Parser parser,
int  argc,
char *  argv[] 
)

helper function for parsing directly from main

Definition at line 1335 of file argparse.cc.

◆ print_parse_error()

void eu::core::argparse::print_parse_error ( Runner runner,
ParserBase base,
const std::string &  error_message 
)

Definition at line 215 of file argparse.cc.

◆ to_string() [1/2]

std::string eu::core::argparse::to_string ( const eu::core::argparse::NameAndArguments args)

Definition at line 143 of file argparse.cc.

◆ to_string() [2/2]

std::string eu::core::argparse::to_string ( const ParseResult pr)

Definition at line 105 of file argparse.cc.

Variable Documentation

◆ error

constexpr ParseResult eu::core::argparse::error = ParseResult{ ParseResult::Type::error }
constexpr

no error occurred

Definition at line 73 of file argparse.h.

◆ ok

constexpr ParseResult eu::core::argparse::ok = ParseResult{ ParseResult::Type::ok }
constexpr

all ok

Definition at line 76 of file argparse.h.

◆ quit

constexpr ParseResult eu::core::argparse::quit = ParseResult{ ParseResult::Type::quit }
constexpr

all ok, but quit requested

Definition at line 79 of file argparse.h.