cli Class Reference

#include <cli.h>


Detailed Description

Configurable command-line interface.

Somewhat experimental.

Default commands: help, get/set, quit, exit, '!', verbose, license, warranty, alias.

Note that if the shell command is allowed (as it is by default) there are some potential security issues which are not solved here.

Commands which begin with a '#' character are ignored.

Definition at line 206 of file cli.h.


Public Member Functions

int set_function (comm_option_funct &usf)
 Function to call when a set command is issued.
virtual char * cli_gets (const char *c)
int call_args (std::vector< cmd_line_arg > &ca)
 Call functions corresponding to command-line args.
int process_args (int argv, const char *argc[], std::vector< cmd_line_arg > &ca, int debug=0)
 Process command-line arguments.
int process_args (std::string s, std::vector< cmd_line_arg > &ca, int debug=0)
 Process command-line arguments.
int set_verbose (int v)
 Set verbosity.
int run_interactive ()
 Run the interactive mode.
int set_comm_option (comm_option &ic)
 Add a new command.
int set_parameters (collection &co)
 Create a new command.
int set_param_help (std::string param, std::string help)
 Set one-line help text for a parameter named param.
int set_alias (std::string alias, std::string str)
 Set an alias alias for the string str.

Data Fields

bool gnu_intro
 If true, output the usual GNU intro when run_interactive() is called.
bool sync_verbose
 If true, then sync verbose, with a parameter of the same name.
bool shell_cmd_allowed
 If true, allow the user to use ! to execute a shell command (default true).
std::string prompt
 The prompt (default "> ").
std::string desc
 A one- or two-line description (default is empty string).
std::string cmd_name
 The name of the command.
std::string addl_help_cmd
 Additional help text for interactive mode (default is empty string).
std::string addl_help_cli
 Additional help text for command-line (default is empty string).
char * line_read
The hard-coded command objects
comm_option c_help
comm_option c_quit
comm_option c_exit
comm_option c_license
comm_option c_warranty
comm_option c_set
comm_option c_get
comm_option c_no_intro
comm_option c_alias

Protected Member Functions

int apply_alias (std::string &s, std::string sold, std::string snew)
 Replace all occurences of sold with snew in s.
int separate (std::string str, std::vector< std::string > &sv)
 Separate a string into words.
bool string_equal (std::string s1, std::string s2)
 Compare two strings, treating dashes as underscores.
The hard-coded command functions
int comm_option_get (std::vector< std::string > &sv, bool itive_com)
int comm_option_set (std::vector< std::string > &sv, bool itive_com)
int comm_option_help (std::vector< std::string > &sv, bool itive_com)
int comm_option_license (std::vector< std::string > &sv, bool itive_com)
int comm_option_warranty (std::vector< std::string > &sv, bool itive_com)
int comm_option_no_intro (std::vector< std::string > &sv, bool itive_com)
int comm_option_alias (std::vector< std::string > &sv, bool itive_com)

Protected Attributes

int verbose
 Control screen output.
collectioncop
 Pointer to collection for parameters.
char buf [300]
 Storage for getline.
comm_option_functuser_set_func
 Storage for the function to call after setting a parameter.
std::vector< comm_option * > clist
 List of commands.
Help for parameters
std::vector< std::string > ph_name
std::vector< std::string > ph_desc
Aliases
std::vector< std::string > al1
std::vector< std::string > al2

Member Function Documentation

int set_verbose ( int  v  ) 

Set verbosity.

Most errors are output to the screen even if verbose is zero.

int set_comm_option ( comm_option ic  ) 

Add a new command.

Each command/option must have either a short form in comm_option::shrt or a long from in comm_option::lng, which is unique from the other commands/options already present. You cannot add two commands/options with the same short form, even if they have different long forms, and vice versa.

int set_parameters ( collection co  ) 

Create a new command.

Set the parameters with a collection

int set_alias ( std::string  alias,
std::string  str 
) [inline]

Set an alias alias for the string str.

Aliases can also be set using the command 'alias', but that version allows only one-word aliases.

Definition at line 382 of file cli.h.


Field Documentation

bool gnu_intro

If true, output the usual GNU intro when run_interactive() is called.

In order to conform to GNU standards, this ought not be set to false by default.

Definition at line 271 of file cli.h.


The documentation for this class was generated from the following file:

Documentation generated with Doxygen and provided under the GNU Free Documentation License. See License Information for details.

Project hosting provided by SourceForge.net Logo, O2scl Sourceforge Project Page