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);
249 virtual int set(std::string s)=0;
252 virtual std::string
get()=0;
267 virtual int set(std::string s) {
273 virtual std::string
get() {
290 virtual int set(std::string s) {
296 virtual std::string
get() {
313 virtual int set(std::string s) {
319 virtual std::string
get() {
336 virtual int set(std::string s) {
342 virtual std::string
get() {
351 std::map<std::string,parameter *,string_comp>
par_list;
353 typedef std::map<std::string,parameter *,string_comp>::iterator
par_t;
356 #ifndef DOXYGEN_NO_O2NS_INTERNAL
371 std::string sold, std::string snew);
390 int separate(std::string str, std::vector<std::string> &sv);
397 int comm_option_alias(std::vector<std::string> &sv,
bool itive_com);
398 int comm_option_commands(std::vector<std::string> &sv,
bool itive_com);
399 int comm_option_get(std::vector<std::string> &sv,
bool itive_com);
400 int comm_option_help(std::vector<std::string> &sv,
bool itive_com);
401 int comm_option_license(std::vector<std::string> &sv,
bool itive_com);
402 int comm_option_no_intro(std::vector<std::string> &sv,
bool itive_com);
403 int comm_option_run(std::vector<std::string> &sv,
bool itive_com);
404 int comm_option_set(std::vector<std::string> &sv,
bool itive_com);
405 int comm_option_warranty(std::vector<std::string> &sv,
bool itive_com);
419 std::vector<std::string> ph_name, ph_desc;
424 std::map<std::string,std::string,string_comp> als;
425 typedef std::map<std::string,std::string,string_comp>::iterator al_it;
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;
517 (
size_t list_size, vec_t &option_list) {
519 for(
size_t k=0;k<list_size;k++) {
521 for(
size_t i=0;found==
false && i<
clist.size();i++) {
523 if ((option_list[k].shrt!=0 &&
524 clist[i].shrt==option_list[k].shrt) ||
525 (option_list[k].lng.length()>0 &&
526 clist[i].lng==option_list[k].lng)) {
532 if (option_list[k].shrt!=0) {
533 std::string err=
"Option ";
534 err+=option_list[k].shrt;
535 err+=((std::string)
" , ")+option_list[k].lng+
" already present.";
538 std::string err=
"Option ";
539 err+=option_list[k].lng+
" already present.";
544 clist.push_back(option_list[k]);
556 int run_auto(
int argc,
char *argv[],
int debug=0);
564 virtual char *
cli_gets(
const char *c);
567 int call_args(std::vector<cmd_line_arg> &ca);
579 std::vector<cmd_line_arg> &ca,
int debug=0);
586 int process_args(std::string s, std::vector<cmd_line_arg> &ca,
606 int set_alias(std::string alias, std::string str);
613 std::string
get_alias(std::string alias);
617 #ifndef DOXYGEN_NO_O2NS
comm_option_mfptr(const comm_option_mfptr &f)
Copy constructor.
Double parameter for o2scl::cli.
comm_option_fptr(int(*fp)(std::vector< std::string > &, bool))
Create from a member function pointer from the specified class.
virtual int set(std::string s)=0
Set from string.
std::string cmd_name
The name of the command.
int apply_alias(std::vector< std::string > &sv, std::string sold, std::string snew)
Replace all occurences of sold with snew in sv.
int run_interactive()
Run the interactive mode.
std::string help
The help description.
int verbose
Control screen output.
String parameter for o2scl::cli.
int output_param_list()
Output the parameter list.
int expand_tilde(std::vector< std::string > &sv)
Attempt to expand a tilde to a user's home directory.
virtual int set(std::string s)
Set from string.
invalid argument supplied by user
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.
std::string lng
Long option (must be specified and must be unique)
int(tclass::* fptr)(std::vector< std::string > &cstr, bool itive_com)
The pointer to the member function.
comm_option_fptr & operator=(const comm_option_fptr &f)
Copy constructor.
Parameter for o2scl::cli.
int process_args(int argc, char *argv[], std::vector< cmd_line_arg > &ca, int debug=0)
Process command-line arguments from a const char array.
std::string get_alias(std::string alias)
Set an alias alias for the string str.
int set_alias(std::string alias, std::string str)
Set an alias alias for the string str.
std::string parm_desc
Description of parameters.
tclass * tptr
The pointer to the class.
int run_auto(int argc, char *argv[], int debug=0)
Automatically parse arguments to main and call interactive mode if required.
std::string btos(bool b)
Convert a boolean value to a string.
comm_option_funct * func
The pointer to the function to be called (or 0 for no function)
int set_function(comm_option_funct &usf)
Function to call when a set command is issued.
std::string addl_help_cli
Additional help text for command-line (default is empty string)
virtual int set(std::string s)
Set from string.
std::string prompt
The prompt (default "> ")
std::string tilde_string
String to replace tildes with.
int type
Type: command-line parameter, command, or both.
Configurable command-line interface.
virtual int operator()(std::vector< std::string > &cstr, bool itive_com)
The basic function called by o2scl::cli.
std::string help
Help description.
virtual int operator()(std::vector< std::string > &cstr, bool itive_com)=0
The basic function called by o2scl::cli.
int stoi(std::string s, bool err_on_fail=true)
Convert a string to an integer.
bool stob(std::string s, bool err_on_fail=true)
Convert a string to a boolean value.
bool is_valid
Is a properly formatted option.
bool shell_cmd_allowed
If true, allow the user to use ! to execute a shell command (default true)
comm_option_mfptr(tclass *tp, int(tclass::*fp)(std::vector< std::string > &, bool))
Create from a member function pointer from the specified class.
int set_param_help(std::string param, std::string help)
Set one-line help text for a parameter named param.
virtual char * cli_gets(const char *c)
The function which obtains input from the user.
comm_option_mfptr & operator=(const comm_option_mfptr &f)
Copy constructor.
A command-line argument for o2scl::cli.
Member function pointer for o2scl::cli command function.
std::string dtos(double x, int prec=6, bool auto_prec=false)
Convert a double to a string.
int min_parms
Minimum number of parameters (0 for none, -1 for variable)
String parameter for o2scl::cli.
virtual int set(std::string s)
Set from string.
int separate(std::string str, std::vector< std::string > &sv)
Separate a string into words, handling quotes.
int set_comm_option(comm_option_s &ic)
Add a new command.
char buf[300]
Storage for getline.
Base for o2scl::cli command function.
std::string * str
Parameter.
int set_verbose(int v)
Set verbosity.
std::vector< comm_option_s > clist
List of commands.
Function pointer for o2scl::cli command function.
#define O2SCL_ERR(d, n)
Set an error with message d and code n.
int set_comm_option_vec(size_t list_size, vec_t &option_list)
Add a vector containing new commands/options.
virtual int set(std::string s)
Set from string.
Integer parameter for o2scl::cli.
int max_parms
Maximum number of parameters (0 for none, -1 for variable)
Command for interactive mode in o2scl::cli.
char shrt
Short option ('\0' for none, must be unique if present)
int call_args(std::vector< cmd_line_arg > &ca)
Call functions corresponding to command-line args.
std::string addl_help_cmd
Additional help text for interactive mode (default is empty string)
bool gnu_intro
If true, output the usual GNU intro when run_interactive() is called (default true).
std::map< std::string, parameter *, string_comp >::iterator par_t
List iterator.
std::map< std::string, parameter *, string_comp > par_list
Parameter list.
comm_option_s * cop
A pointer to the appropriate option (0, unless it's an option)
bool is_option
Is an option?
bool sync_verbose
If true, then sync cli::verbose, with a parameter of the same name.
int(* fptr)(std::vector< std::string > &cstr, bool itive_com)
The pointer to the member function.
virtual int operator()(std::vector< std::string > &cstr, bool itive_com)
The basic function called by o2scl::cli.
double stod(std::string s, bool err_on_fail=true)
Convert a string to a double.
std::string itos(int x)
Convert an integer to a string.
comm_option_funct * user_set_func
Storage for the function to call after setting a parameter.
std::string desc
Description for help.
std::vector< std::string > parms
List of parameters (empty, unless it's an option)
std::string arg
The argument.