wex  v21.04.0
Public Types | Public Member Functions | List of all members
wex::cmdline Class Reference

This class offers a command line parser. More...

#include <wex/cmdline.h>

Public Types

enum  option_t { FLOAT , INT , STRING }
 Types for command line options. More...
 
typedef std::vector< std::pair< const std::vector< std::string >, std::function< void(bool on)> > > cmd_switches_t
 Switches:
 
typedef std::vector< std::pair< const std::vector< std::string >, std::pair< option_t, std::function< void(const std::any &any)> > > > cmd_options_t
 Options:
 
typedef std::pair< const std::pair< const std::string, const std::string >, std::function< void(std::vector< std::string >)> > cmd_params_t
 Params (currently only string value supported):
 

Public Member Functions

 cmdline (const cmd_switches_t &s=cmd_switches_t(), const cmd_options_t &o=cmd_options_t(), const cmd_params_t &p=cmd_params_t(), bool add_standard_options=true, const std::string &prefix=std::string())
 Default constructor, adds standard options. More...
 
 ~cmdline ()
 Destructor.
 
bool parse (data::cmdline &data)
 Parses the command line arguments and invokes callbacks. More...
 
bool parse_set (data::cmdline &data) const
 Parses the command line arguments and invokes callbacks. More...
 

Detailed Description

This class offers a command line parser.

Member Enumeration Documentation

◆ option_t

Types for command line options.

Enumerator
FLOAT 

option is a float value

INT 

option is a int value

STRING 

option is a string value

Constructor & Destructor Documentation

◆ cmdline()

wex::cmdline::cmdline ( const cmd_switches_t s = cmd_switches_t(),
const cmd_options_t o = cmd_options_t(),
const cmd_params_t p = cmd_params_t(),
bool  add_standard_options = true,
const std::string &  prefix = std::string() 
)

Default constructor, adds standard options.

Parameters
sswitches
ooptions
pparams
add_standard_optionsadd standard options
prefixoption prefix for all options

Member Function Documentation

◆ parse()

bool wex::cmdline::parse ( data::cmdline data)

Parses the command line arguments and invokes callbacks.

Returns false if error is found, or exit condition is true.

◆ parse_set()

bool wex::cmdline::parse_set ( data::cmdline data) const

Parses the command line arguments and invokes callbacks.

Options are specified according to ex :set specification. [option[=[value]] ...][nooption ...][option? ...][all] Returns false if option was not found.