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) {
326 virtual std::string
get() {
343 virtual int set(std::string s) {
349 virtual std::string
get() {
366 virtual int set(std::string st) {
371 virtual std::string
get() {
380 std::map<std::string,parameter *,std::less<std::string> >
par_list;
382 typedef std::map<std::string,
parameter *,
383 std::greater<std::string> >::iterator
par_t;
386 #ifndef DOXYGEN_NO_O2NS_INTERNAL 391 int output_param_list();
397 int expand_tilde(std::vector<std::string> &sv);
400 int apply_alias(std::vector<std::string> &sv,
401 std::string sold, std::string snew);
417 std::vector<std::string> ph_name, ph_desc;
422 std::map<std::string,std::string,std::greater<std::string> > als;
423 typedef std::map<std::string,std::string,
424 std::greater<std::string> >::iterator al_it;
428 bool string_equal_dash(std::string s1, std::string s2);
440 int comm_option_alias(std::vector<std::string> &sv,
bool itive_com);
441 int comm_option_commands(std::vector<std::string> &sv,
bool itive_com);
442 int comm_option_get(std::vector<std::string> &sv,
bool itive_com);
443 int comm_option_help(std::vector<std::string> &sv,
bool itive_com);
444 int comm_option_license(std::vector<std::string> &sv,
bool itive_com);
445 int comm_option_no_intro(std::vector<std::string> &sv,
bool itive_com);
446 int comm_option_run(std::vector<std::string> &sv,
bool itive_com);
447 int comm_option_set(std::vector<std::string> &sv,
bool itive_com);
448 int comm_option_warranty(std::vector<std::string> &sv,
bool itive_com);
470 static const int comm_option_command=0;
471 static const int comm_option_cl_param=1;
472 static const int comm_option_both=2;
529 void remove_comm_option(std::string cmd);
532 template<
class vec_t>
int set_comm_option_vec
533 (
size_t list_size, vec_t &option_list) {
535 for(
size_t k=0;k<list_size;k++) {
537 if (option_list[k].lng.length()<2) {
538 std::string str=((std::string)
"Long option '")+option_list[k].lng+
539 "' does not have at "+
540 "least two characters in cli::set_comm_option().";
545 for(
size_t i=0;found==
false && i<clist.size();i++) {
547 if ((option_list[k].shrt!=0 &&
548 clist[i].shrt==option_list[k].shrt) ||
549 (option_list[k].lng.length()>0 &&
550 clist[i].lng==option_list[k].lng)) {
556 if (option_list[k].shrt!=0) {
557 std::string err=
"Option ";
558 err+=option_list[k].shrt;
559 err+=((std::string)
" , ")+option_list[k].lng+
" already present.";
562 std::string err=
"Option ";
563 err+=option_list[k].lng+
" already present.";
568 clist.push_back(option_list[k]);
575 int set_param_help(std::string param, std::string help);
580 int run_auto(
int argc,
char *argv[],
int debug=0);
588 virtual char *cli_gets(
const char *c);
591 int call_args(std::vector<cmd_line_arg> &ca,
int debug=0);
602 int process_args(
int argc,
char *argv[],
603 std::vector<cmd_line_arg> &ca,
int debug=0,
604 bool also_call_args=
false);
612 int process_args(std::vector<std::string> &sv,
613 std::vector<cmd_line_arg> &ca,
int debug);
620 int process_args(std::string s, std::vector<cmd_line_arg> &ca,
621 int debug=0,
bool also_call_args=
false);
627 int set_verbose(
int v);
630 int run_interactive();
640 int set_alias(std::string alias, std::string str);
647 std::string get_alias(std::string alias);
651 #ifndef DOXYGEN_NO_O2NS comm_option_mfptr(const comm_option_mfptr &f)
Copy constructor.
int stoszt_nothrow(std::string s, size_t &result)
Convert a string to a size_t without throwing an exception.
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.
std::string cmd_name
The name of the command.
The main O<span style='position: relative; top: 0.3em; font-size: 0.8em'>2</span>scl O$_2$scl names...
Integer parameter for o2scl::cli.
std::string help
The help description.
int verbose
Control screen output.
String parameter for o2scl::cli.
invalid argument supplied by user
std::string desc
A one- or two-line description (default is empty string)
std::string lng
Long option (must be specified and must be unique)
comm_option_fptr & operator=(const comm_option_fptr &f)
Copy constructor.
Parameter for o2scl::cli.
std::string parm_desc
Description of parameters.
tclass * tptr
The pointer to the class.
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)
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.
std::map< std::string, parameter *, std::greater< std::string > >::iterator par_t
List iterator.
bool stob(std::string s, bool err_on_fail=true)
Convert a string to a boolean value.
double function_to_double(std::string s)
Convert a formula to a double.
int(tclass::* fptr)(std::vector< std::string > &cstr, bool itive_com)
The pointer to the member function.
bool is_valid
Is a properly formatted option.
int(* fptr)(std::vector< std::string > &cstr, bool itive_com)
The pointer to the member function.
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.
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.
Base for o2scl::cli command function.
std::string * str
Parameter.
std::map< std::string, parameter *, std::less< std::string > > par_list
Parameter list.
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.
Integer parameter for o2scl::cli.
int max_parms
Maximum number of parameters (0 for none, -1 for variable)
double stod(std::string s)
Convert a string to a double.
Command for interactive mode in o2scl::cli.
char shrt
Short option ('\0' for none, must be unique if present)
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).
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.
virtual int operator()(std::vector< std::string > &cstr, bool itive_com)
The basic function called by o2scl::cli.
bool parse_strings
If true,.
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 szttos(size_t x)
Convert a size_t to a string.
std::string desc
Description for help.
std::vector< std::string > parms
List of parameters (empty, unless it's an option)
int stoi(std::string s)
Convert a string to an integer.
std::string arg
The argument.