wex v24.10.0
Public Types | Public Member Functions | Static Public Member Functions | List of all members
wex::cmdline Class Reference

Offers a command line class. More...

#include <wex/core/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)
 Default constructor, adds standard options.
 
 ~cmdline ()
 Destructor.
 
bool parse (data::cmdline &data)
 Parses the command line arguments and invokes callbacks.
 
bool parse_set (data::cmdline &data) const
 Parses the command line arguments and invokes callbacks.
 

Static Public Member Functions

static std::string get_output ()
 Returns output.
 
static std::string get_scriptout ()
 Returns script out.
 
static bool is_echo ()
 Returns echo.
 
static bool is_output ()
 Returns output.
 
static bool use_events ()
 For some tests events can be preferred over direct code.
 

Detailed Description

Offers a command line class.

Besides offering the switches, options and params, it also adds standard options:

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 )

Default constructor, adds standard options.

Parameters
sswitches
ooptions
pparams
add_standard_optionsadd standard 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.

◆ use_events()

static bool wex::cmdline::use_events ( )
static

For some tests events can be preferred over direct code.

Returns this setting, default events are not preferred.