wex v26.04.0
wex::cmdline Class Reference

Offers a command line class, that supports switches, options and params. 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 (cmd_switches_t s=cmd_switches_t(), cmd_options_t o=cmd_options_t(), cmd_params_t p=cmd_params_t(), bool add_standard_options=true)
 Default constructor, adds next 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, that supports switches, options and params.

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 ( cmd_switches_t s = cmd_switches_t(),
cmd_options_t o = cmd_options_t(),
cmd_params_t p = cmd_params_t(),
bool add_standard_options = true )

Default constructor, adds next options:

  • help,h: sets usage information and sets exit condition
  • version,R: sets version information and sets exit condition
Parameters
sswitches
ooptions
pparams
add_standard_optionsif specified, adds the next options:
  • logfile,D: sets log file
  • echo,e: echo commands (sets is_output)
  • quit,q: quits after specified number of seconds
  • verbose,v: activates maximum (trace) verbosity
  • level,V: activates verbosity down from verbose level
  • scriptout,w: script out append (echo to file) (sets get_scriptout)
  • echo-output,x: echo output commands (process, statusbar) (sets is_echo)
  • output,X: output commands append to file (sets get_output)

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()

bool wex::cmdline::use_events ( )
static

For some tests events can be preferred over direct code.

Returns this setting, default events are not preferred.