Go to the documentation of this file.
35 #include <o2scl/columnify.h>
36 #include <o2scl/vector.h>
37 #include <o2scl/string_conv.h>
39 #ifndef DOXYGEN_NO_O2NS
56 virtual int operator()(std::vector<std::string> &cstr,
bool itive_com)=0;
73 virtual int operator()(std::vector<std::string> &cstr,
bool itive_com) {
74 return (*
fptr)(cstr,itive_com);
77 #ifndef DOXYGEN_INTERNAL
82 int (*
fptr)(std::vector<std::string> &cstr,
bool itive_com);
114 virtual int operator()(std::vector<std::string> &cstr,
bool itive_com) {
115 return (*
tptr.*
fptr)(cstr,itive_com);
118 #ifndef DOXYGEN_INTERNAL
123 int (tclass::*
fptr)(std::vector<std::string> &cstr,
bool itive_com);
245 virtual int set(std::string s)=0;
248 virtual std::string
get()=0;
263 virtual int set(std::string s) {
269 virtual std::string
get() {
286 virtual int set(std::string s) {
292 virtual std::string
get() {
316 virtual int set(std::string s);
319 virtual std::string
get() {
336 virtual int set(std::string s) {
342 virtual std::string
get() {
359 virtual int set(std::string st) {
364 virtual std::string
get() {
373 std::map<std::string,parameter *,std::less<std::string> >
par_list;
375 typedef std::map<std::string,
parameter *,
376 std::greater<std::string> >::iterator
par_t;
379 #ifndef DOXYGEN_NO_O2NS_INTERNAL
400 std::vector<std::string> ph_name, ph_desc;
405 std::map<std::string,std::string,std::greater<std::string> > als;
406 typedef std::map<std::string,std::string,
407 std::greater<std::string> >::iterator al_it;
423 int comm_option_alias(std::vector<std::string> &sv,
bool itive_com);
424 int comm_option_commands(std::vector<std::string> &sv,
bool itive_com);
425 int comm_option_get(std::vector<std::string> &sv,
bool itive_com);
426 int comm_option_help(std::vector<std::string> &sv,
bool itive_com);
427 int comm_option_license(std::vector<std::string> &sv,
bool itive_com);
428 int comm_option_no_intro(std::vector<std::string> &sv,
bool itive_com);
429 int comm_option_run(std::vector<std::string> &sv,
bool itive_com);
430 int comm_option_shell(std::vector<std::string> &sv,
bool itive_com);
431 int comm_option_set(std::vector<std::string> &sv,
bool itive_com);
432 int comm_option_warranty(std::vector<std::string> &sv,
bool itive_com);
436 int apply_aliases(std::vector<std::string> &sv,
size_t istart,
458 static const int comm_option_command=0;
459 static const int comm_option_cl_param=1;
460 static const int comm_option_both=2;
522 (
size_t list_size, vec_t &option_list) {
524 for(
size_t k=0;k<list_size;k++) {
526 if (option_list[k].lng.length()<2) {
527 std::string str=((std::string)
"Long option '")+option_list[k].lng+
528 "' does not have at "+
529 "least two characters in cli::set_comm_option().";
534 for(
size_t i=0;found==
false && i<
clist.size();i++) {
536 if ((option_list[k].shrt!=0 &&
537 clist[i].shrt==option_list[k].shrt) ||
538 (option_list[k].lng.length()>0 &&
539 clist[i].lng==option_list[k].lng)) {
545 if (option_list[k].shrt!=0) {
546 std::string err=
"Option ";
547 err+=option_list[k].lng+
" ('";
548 err+=option_list[k].shrt;
549 err+=
"') already present.";
552 std::string err=
"Option ";
553 err+=option_list[k].lng+
" already present.";
558 clist.push_back(option_list[k]);
570 int run_auto(
int argc,
char *argv[],
int debug=0);
578 virtual char *
cli_gets(
const char *c);
581 int call_args(std::vector<cmd_line_arg> &ca,
int debug=0);
593 std::vector<cmd_line_arg> &ca,
int debug=0,
594 bool also_call_args=
false);
596 int parse_for_aliases(std::vector<std::string> &svsv);
605 std::vector<cmd_line_arg> &ca,
int debug,
606 bool also_call_args=
false);
614 int debug=0,
bool also_call_args=
false);
633 int set_alias(std::string alias, std::string str);
640 std::string
get_alias(std::string alias);
648 #ifndef DOXYGEN_NO_O2NS
Integer parameter for o2scl::cli.
int(tclass::* fptr)(std::vector< std::string > &cstr, bool itive_com)
The pointer to the member function.
std::string cmd_name
The name of the command.
bool parse_strings
If true, use value_spec() to convert strings to doubles.
std::string dtos(const fp_t &x, int prec=6, bool auto_prec=false)
Convert a double to a string.
comm_option_fptr(int(*fp)(std::vector< std::string > &, bool))
Create from a member function pointer from the specified class.
std::string btos(bool b)
Convert a boolean value to a string.
char buf[300]
Storage for getline.
A command-line argument for o2scl::cli.
std::string lng
Long option (must be specified and must be unique)
bool is_valid
Is a properly formatted option.
std::string get_alias(std::string alias)
Set an alias alias for the string str.
virtual std::string get()=0
Convert to string.
@ exc_efailed
generic failure
virtual int operator()(std::vector< std::string > &cstr, bool itive_com)
The basic function called by o2scl::cli.
std::map< std::string, parameter *, std::greater< std::string > >::iterator par_t
List iterator.
int process_args(std::vector< std::string > &sv, std::vector< cmd_line_arg > &ca, int debug, bool also_call_args=false)
Process command-line arguments from a vector of strings.
int stoi(std::string s)
Convert a string to an integer.
tclass * tptr
The pointer to the class.
comm_option_funct * func
The pointer to the function to be called (or 0 for no function)
bool is_valid_option(std::string str)
Return true if str is a valid option.
std::string help
The help description.
int apply_aliases(std::vector< std::string > &sv, size_t istart, bool debug=false)
Replace all occurences of sold with snew in sv.
The main O<span style='position: relative; top: 0.3em; font-size: 0.8em'>2</span>scl O$_2$scl names...
virtual int set(std::string s)
Set from string.
Base for o2scl::cli command function.
std::string arg
The argument.
virtual int set(std::string st)
Set from string.
bool sync_verbose
If true, then sync cli::verbose, with a parameter of the same name.
std::string desc
A one- or two-line description (default is empty string)
bool string_equal_dash(std::string s1, std::string s2)
Compare two strings, treating dashes and underscores as equivalent.
virtual std::string get()
Convert to string.
int set_param_help(std::string param, std::string help)
Set one-line help text for a parameter named param.
virtual std::string get()
Convert to string.
std::string tilde_string
String to replace tildes with.
std::string parm_desc
Description of parameters.
String parameter for o2scl::cli.
String parameter for o2scl::cli.
int call_args(std::vector< cmd_line_arg > &ca, int debug=0)
Call functions corresponding to command-line args.
int set_comm_option(comm_option_s &ic)
Add a new command.
bool gnu_intro
If true, output the usual GNU intro when run_interactive() is called (default true).
std::string addl_help_cmd
Additional help text for interactive mode (default is empty string)
virtual std::string get()
Convert to string.
int min_parms
Minimum number of parameters (0 for none, -1 for variable)
std::map< std::string, parameter *, std::less< std::string > > par_list
Parameter list.
int set_verbose(int v)
Set verbosity.
comm_option_mfptr(const comm_option_mfptr &f)
Copy constructor.
@ exc_einval
invalid argument supplied by user
int set_alias(std::string alias, std::string str)
Set an alias alias for the string str.
virtual int set(std::string s)
Set from string.
virtual int operator()(std::vector< std::string > &cstr, bool itive_com)=0
The basic function called by o2scl::cli.
comm_option_fptr & operator=(const comm_option_fptr &f)
Copy constructor.
int type
Type: command-line parameter, command, or both.
int set_function(comm_option_funct &usf)
Function to call when a set command is issued.
Integer parameter for o2scl::cli.
comm_option_s * cop
A pointer to the appropriate option (0, unless it's an option)
virtual std::string get()
Convert to string.
Command for interactive mode in o2scl::cli.
virtual int set(std::string s)
Set from string.
Configurable command-line interface.
void remove_comm_option(std::string cmd)
Remove a command with long name cmd.
Double parameter for o2scl::cli.
virtual int operator()(std::vector< std::string > &cstr, bool itive_com)
The basic function called by o2scl::cli.
int(* fptr)(std::vector< std::string > &cstr, bool itive_com)
The pointer to the member function.
int process_args_str(std::string s, std::vector< cmd_line_arg > &ca, int debug=0, bool also_call_args=false)
Process command-line arguments from a string.
Parameter for o2scl::cli.
int stoszt_nothrow(std::string s, size_t &result)
Convert a string to a size_t without throwing an exception.
Member function pointer for o2scl::cli command function.
virtual int set(std::string s)
Set from string.
std::string itos(int x)
Convert an integer to a string.
char shrt
Short option ('\0' for none, must be unique if present)
virtual std::string get()
Convert to string.
std::string prompt
The prompt (default "> ")
int run_auto(int argc, char *argv[], int debug=0)
Automatically parse arguments to main and call interactive mode if required.
#define O2SCL_ERR(d, n)
Set an error with message d and code n.
int run_interactive()
Run the interactive mode.
std::vector< comm_option_s > clist
List of commands.
std::string * str
Parameter.
int verbose
Control screen output.
int output_param_list()
Output the parameter list.
comm_option_mfptr(tclass *tp, int(tclass::*fp)(std::vector< std::string > &, bool))
Create from a member function pointer from the specified class.
int max_parms
Maximum number of parameters (0 for none, -1 for variable)
comm_option_funct * user_set_func
Storage for the function to call after setting a parameter.
std::vector< std::string > parms
List of parameters (empty, unless it's an option)
bool is_option
Is an option?
int set_comm_option_vec(size_t list_size, vec_t &option_list)
Add a vector containing new commands/options.
bool shell_cmd_allowed
If true, allow the user to use ! to execute a shell command (default true)
std::string addl_help_cli
Additional help text for command-line (default is empty string)
bool stob(std::string s, bool err_on_fail=true)
Convert a string to a boolean value.
std::string desc
Description for help.
std::string szttos(size_t x)
Convert a size_t to a string.
Function pointer for o2scl::cli command function.
comm_option_mfptr & operator=(const comm_option_mfptr &f)
Copy constructor.
std::string help
Help description.
int process_args_c(int argc, char *argv[], std::vector< cmd_line_arg > &ca, int debug=0, bool also_call_args=false)
Process command-line arguments from a const char array.
virtual int set(std::string s)=0
Set from string.
virtual char * cli_gets(const char *c)
The function which obtains input from the user.
Documentation generated with Doxygen. Provided under the
GNU Free Documentation License (see License Information).