cli.h
Go to the documentation of this file.
1 /*
2  -------------------------------------------------------------------
3 
4  Copyright (C) 2006-2020, Andrew W. Steiner
5 
6  This file is part of O2scl.
7 
8  O2scl is free software; you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation; either version 3 of the License, or
11  (at your option) any later version.
12 
13  O2scl is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with O2scl. If not, see <http://www.gnu.org/licenses/>.
20 
21  -------------------------------------------------------------------
22 */
23 /** \file cli.h
24  \brief File defining command-line interface in \ref o2scl::cli
25 */
26 #ifndef O2SCL_CLI_H
27 #define O2SCL_CLI_H
28 
29 #include <iostream>
30 #include <vector>
31 #include <algorithm>
32 #include <sstream>
33 #include <map>
34 
35 #include <o2scl/columnify.h>
36 #include <o2scl/vector.h>
37 #include <o2scl/string_conv.h>
38 
39 #ifndef DOXYGEN_NO_O2NS
40 namespace o2scl {
41 #endif
42 
43  /** \brief Base for \ref o2scl::cli command function
44 
45  See the \ref o2scl::cli class for more details.
46  */
48 
49  public:
50 
52 
53  virtual ~comm_option_funct() {}
54 
55  /// The basic function called by \ref o2scl::cli
56  virtual int operator()(std::vector<std::string> &cstr, bool itive_com)=0;
57 
58  };
59 
60  /// Function pointer for \ref o2scl::cli command function
62 
63  public:
64 
65  /// Create from a member function pointer from the specified class
66  comm_option_fptr(int (*fp)(std::vector<std::string> &, bool)) {
67  fptr=fp;
68  }
69 
70  virtual ~comm_option_fptr() {}
71 
72  /// The basic function called by \ref o2scl::cli
73  virtual int operator()(std::vector<std::string> &cstr, bool itive_com) {
74  return (*fptr)(cstr,itive_com);
75  }
76 
77 #ifndef DOXYGEN_INTERNAL
78 
79  protected:
80 
81  /// The pointer to the member function
82  int (*fptr)(std::vector<std::string> &cstr, bool itive_com);
83 
84  // Copy constructor
85  //comm_option_fptr(const comm_option_fptr &f) {
86  //fptr=f.fptr;
87  //}
88 
89  /// Copy constructor
91  fptr=f.fptr;
92  return *this;
93  }
94 
95 #endif
96 
97  };
98 
99  /// Member function pointer for \ref o2scl::cli command function
100  template<class tclass> class comm_option_mfptr : public comm_option_funct {
101 
102  public:
103 
104  /// Create from a member function pointer from the specified class
105  comm_option_mfptr(tclass *tp, int (tclass::*fp)(std::vector<std::string> &,
106  bool)) {
107  tptr=tp;
108  fptr=fp;
109  }
110 
111  virtual ~comm_option_mfptr() {}
112 
113  /// The basic function called by \ref o2scl::cli
114  virtual int operator()(std::vector<std::string> &cstr, bool itive_com) {
115  return (*tptr.*fptr)(cstr,itive_com);
116  }
117 
118 #ifndef DOXYGEN_INTERNAL
119 
120  protected:
121 
122  /// The pointer to the member function
123  int (tclass::*fptr)(std::vector<std::string> &cstr, bool itive_com);
124 
125  /// The pointer to the class
126  tclass *tptr;
127 
128  /// Copy constructor
130  fptr=f.fptr;
131  tptr=f.tptr;
132  }
133 
134  /// Copy constructor
136  fptr=f.fptr;
137  tptr=f.tptr;
138  return *this;
139  }
140 
141 #endif
142 
143  };
144 
145  /** \brief Command for interactive mode in \ref o2scl::cli
146 
147  See the \ref o2scl::cli class for more details.
148 
149  \comment
150  This was at one point converted into a class, but it wasn't that
151  easy to use, in comparison to structs which are easy to
152  initialize in aggregate.
153  \endcomment
154  */
155  typedef struct {
156 
157  /// Short option (\c '\\0' for none, must be unique if present)
158  char shrt;
159  /// Long option (must be specified and must be unique)
160  std::string lng;
161  /// Description for help
162  std::string desc;
163  /// Minimum number of parameters (0 for none, -1 for variable)
165  /// Maximum number of parameters (0 for none, -1 for variable)
167  /// Description of parameters
168  std::string parm_desc;
169  /// The help description
170  std::string help;
171  /// The pointer to the function to be called (or 0 for no function)
173  /// Type: command-line parameter, command, or both
174  int type;
175 
176  } comm_option_s;
177 
178  /** \brief A command-line argument for \ref o2scl::cli
179 
180  This is the internal structure that \ref o2scl::cli uses to package
181  command-line arguments.
182  */
183  typedef struct {
184  /// The argument
185  std::string arg;
186  /// Is an option?
187  bool is_option;
188  /// Is a properly formatted option
189  bool is_valid;
190  /// List of parameters (empty, unless it's an option)
191  std::vector<std::string> parms;
192  /// A pointer to the appropriate option (0, unless it's an option)
194  } cmd_line_arg;
195 
196  /** \brief Configurable command-line interface
197 
198  This class is experimental.
199 
200  Default commands: help, get/set, quit, exit, '!', verbose, license,
201  warranty, alias, run.
202 
203  Note that if the shell command is allowed (as it is by default)
204  there are some potential security issues which are not solved
205  here.
206 
207  Commands which begin with a '#' character are ignored.
208 
209  \note In interactive mode, commands are limited to 300 characters.
210 
211  \future Warn in run_interactive() when extra parameters are given
212  \future Include a "remove command" function
213  \future A replace command function, there's already some code
214  in cli.cpp for this.
215  \future There's some code duplication between comm_option_run()
216  and run_interactive()
217  \future Allow the user to set the tilde string
218  \future Disallow direct access to \ref o2scl::cli::par_list in order to
219  ensure parameter names do not contain whitespace
220 
221  <b>Concepts</b>
222 
223  As a matter of definition, the command-line arguments are simply
224  called arguments. These arguments may be options (in which case
225  they begin with either one dash or two) or parameters to these
226  options. When run in interactive mode, these options are also
227  commands.
228 
229  */
230  class cli {
231 
232  public:
233 
234  /// Parameter for \ref o2scl::cli
235  class parameter {
236 
237  public:
238 
239  virtual ~parameter() {}
240 
241  /// Help description
242  std::string help;
243 
244  /// Set from string
245  virtual int set(std::string s)=0;
246 
247  /// Convert to string
248  virtual std::string get()=0;
249 
250  };
251 
252  /// String parameter for \ref o2scl::cli
253  class parameter_string : public parameter {
254 
255  public:
256 
257  virtual ~parameter_string() {}
258 
259  /// Parameter
260  std::string *str;
261 
262  /// Set from string
263  virtual int set(std::string s) {
264  *str=s;
265  return 0;
266  }
267 
268  /// Convert to string
269  virtual std::string get() {
270  return *str;
271  }
272 
273  };
274 
275  /// String parameter for \ref o2scl::cli
276  class parameter_bool : public parameter {
277 
278  public:
279 
280  virtual ~parameter_bool() {}
281 
282  /// Parameter
283  bool *b;
284 
285  /// Set from string
286  virtual int set(std::string s) {
287  *b=o2scl::stob(s);
288  return 0;
289  }
290 
291  /// Convert to string
292  virtual std::string get() {
293  return btos(*b);
294  }
295 
296  };
297 
298  /// Double parameter for \ref o2scl::cli
299  class parameter_double : public parameter {
300 
301  public:
302 
303  parameter_double() {
304  parse_strings=true;
305  }
306 
307  virtual ~parameter_double() {}
308 
309  /// Parameter
310  double *d;
311 
312  /// If true, use value_spec() to convert strings to doubles
314 
315  /// Set from string
316  virtual int set(std::string s);
317 
318  /// Convert to string
319  virtual std::string get() {
320  return dtos(*d);
321  }
322 
323  };
324 
325  /// Integer parameter for \ref o2scl::cli
326  class parameter_int : public parameter {
327 
328  public:
329 
330  virtual ~parameter_int() {}
331 
332  /// Parameter
333  int *i;
334 
335  /// Set from string
336  virtual int set(std::string s) {
337  *i=o2scl::stoi(s);
338  return 0;
339  }
340 
341  /// Convert to string
342  virtual std::string get() {
343  return itos(*i);
344  }
345 
346  };
347 
348  /// Integer parameter for \ref o2scl::cli
349  class parameter_size_t : public parameter {
350 
351  public:
352 
353  virtual ~parameter_size_t() {}
354 
355  /// Parameter
356  size_t *s;
357 
358  /// Set from string
359  virtual int set(std::string st) {
360  return o2scl::stoszt_nothrow(st,*s);
361  }
362 
363  /// Convert to string
364  virtual std::string get() {
365  return szttos(*s);
366  }
367 
368  };
369 
370  /// \name Parameter storage and associated iterator type
371  //@{
372  /// Parameter list
373  std::map<std::string,parameter *,std::less<std::string> > par_list;
374  /// List iterator
375  typedef std::map<std::string,parameter *,
376  std::greater<std::string> >::iterator par_t;
377  //@}
378 
379 #ifndef DOXYGEN_NO_O2NS_INTERNAL
380 
381  protected:
382 
383  /// Output the parameter list
384  int output_param_list();
385 
386  /// Control screen output
387  int verbose;
388 
389  /// Storage for getline
390  char buf[300];
391 
392  /// Storage for the function to call after setting a parameter
394 
395  /// List of commands
396  std::vector<comm_option_s> clist;
397 
398  /// \name Help for parameters
399  //@{
400  std::vector<std::string> ph_name, ph_desc;
401  //@}
402 
403  /// \name Aliases
404  //@{
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;
408  //@}
409 
410  /// Compare two strings, treating dashes and underscores as equivalent
411  bool string_equal_dash(std::string s1, std::string s2);
412 
413 #endif
414 
415  public:
416 
417  cli();
418 
419  virtual ~cli();
420 
421  /// \name The hard-coded command functions
422  //@{
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);
433  //@}
434 
435  /// Replace all occurences of \c sold with \c snew in \c sv
436  int apply_aliases(std::vector<std::string> &sv, size_t istart,
437  bool debug=false);
438 
439  /// String to replace tildes with
440  std::string tilde_string;
441 
442  /** \brief If true, output the usual GNU intro when run_interactive()
443  is called (default true).
444 
445  In order to conform to GNU standards, this ought not be set to
446  false by default.
447  */
448  bool gnu_intro;
449 
450  /// Function to call when a \c set command is issued
452  user_set_func=&usf;
453  return 0;
454  }
455 
456  /// \name Value to indicate whether commands are also command-line options
457  //@{
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;
461  //@}
462 
463  /// \name The default command objects
464  //@{
465  comm_option_s c_commands;
466  comm_option_s c_help;
467  comm_option_s c_quit;
468  comm_option_s c_exit;
469  comm_option_s c_license;
470  comm_option_s c_warranty;
471  comm_option_s c_set;
472  comm_option_s c_get;
473  comm_option_s c_run;
474  comm_option_s c_shell;
475  comm_option_s c_no_intro;
476  comm_option_s c_alias;
477  //@}
478 
479  /// If true, then sync cli::verbose, with a parameter of the same name
481 
482  /** \brief If true, allow the user to use ! to execute a shell command
483  (default true)
484  */
486 
487  /// The prompt (default <tt>"> "</tt>)
488  std::string prompt;
489 
490  /// A one- or two-line description (default is empty string)
491  std::string desc;
492 
493  /// The name of the command
494  std::string cmd_name;
495 
496  /// Additional help text for interactive mode (default is empty string)
497  std::string addl_help_cmd;
498 
499  /// Additional help text for command-line (default is empty string)
500  std::string addl_help_cli;
501 
502  /// \name Basic operation
503  //@{
504  /** \brief Add a new command
505 
506  Each command/option must have either a short form in
507  comm_option_s::shrt or a long from in comm_option_s::lng,
508  which is unique from the other commands/options already
509  present. You cannot add two commands/options with the same
510  short form, even if they have different long forms, and vice
511  versa.
512 
513  */
515 
516  /** \brief Remove a command with long name \c cmd
517  */
518  void remove_comm_option(std::string cmd);
519 
520  /// Add a vector containing new commands/options
521  template<class vec_t> int set_comm_option_vec
522  (size_t list_size, vec_t &option_list) {
523 
524  for(size_t k=0;k<list_size;k++) {
525 
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().";
530  O2SCL_ERR(str.c_str(),exc_efailed);
531  }
532 
533  bool found=false;
534  for(size_t i=0;found==false && i<clist.size();i++) {
535  // If short or long options match
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)) {
540  found=true;
541  }
542  }
543  if (found==true) {
544  // Call the error handler
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.";
550  O2SCL_ERR(err.c_str(),exc_einval);
551  } else {
552  std::string err="Option ";
553  err+=option_list[k].lng+" already present.";
554  O2SCL_ERR(err.c_str(),exc_einval);
555  }
556  }
557  // Add the option to the option list
558  clist.push_back(option_list[k]);
559  }
560 
561  return 0;
562  }
563 
564  /// Set one-line help text for a parameter named \c param
565  int set_param_help(std::string param, std::string help);
566 
567  /** \brief Automatically parse arguments to main and
568  call interactive mode if required
569  */
570  int run_auto(int argc, char *argv[], int debug=0);
571  //@}
572 
573  /** \brief The function which obtains input from the user
574 
575  \future Think about whether or not this should be protected?
576  (Possibly not, as it's extensively used by acolm.cpp)
577  */
578  virtual char *cli_gets(const char *c);
579 
580  /// Call functions corresponding to command-line args
581  int call_args(std::vector<cmd_line_arg> &ca, int debug=0);
582 
583  /** \brief Process command-line arguments from a const char array
584 
585  This doesn't actually execute the functions for the
586  corresponding options, but simply processes the parameters \c
587  argv and \c argv and packs the information into \c ca.
588 
589  This function assumes that <tt>argc[0]</tt> just contains
590  the name of the command, and should thus be ignored.
591  */
592  int process_args_c(int argc, char *argv[],
593  std::vector<cmd_line_arg> &ca, int debug=0,
594  bool also_call_args=false);
595 
596  int parse_for_aliases(std::vector<std::string> &svsv);
597 
598  /** \brief Process command-line arguments from a vector of strings
599 
600  This doesn't actually execute the functions for the
601  corresponding options, but simply processes the arguments in
602  \c sv and packs the information into \c ca.
603  */
604  int process_args(std::vector<std::string> &sv,
605  std::vector<cmd_line_arg> &ca, int debug,
606  bool also_call_args=false);
607 
608  /** \brief Process command-line arguments from a string
609 
610  \future There's a typecast in this function to (char *)
611  from (const char *) which needs reworking.
612  */
613  int process_args_str(std::string s, std::vector<cmd_line_arg> &ca,
614  int debug=0, bool also_call_args=false);
615 
616  /** \brief Set verbosity
617 
618  Most errors are output to the screen even if verbose is zero.
619  */
620  int set_verbose(int v);
621 
622  /// Run the interactive mode
623  int run_interactive();
624 
625  // Create a new command
626  // int replace_command(comm_option &ic);
627 
628  /** \brief Set an alias \c alias for the string \c str
629 
630  Aliases can also be set using the command \c 'alias', but
631  that version allows only one-word aliases.
632  */
633  int set_alias(std::string alias, std::string str);
634 
635  /** \brief Set an alias \c alias for the string \c str
636 
637  Aliases can also be set using the command \c 'alias', but
638  that version allows only one-word aliases.
639  */
640  std::string get_alias(std::string alias);
641 
642  /** \brief Return true if \c str is a valid option
643  */
644  bool is_valid_option(std::string str);
645 
646  };
647 
648 #ifndef DOXYGEN_NO_O2NS
649 }
650 #endif
651 
652 #endif
o2scl::cli::parameter_size_t
Integer parameter for o2scl::cli.
Definition: cli.h:349
o2scl::comm_option_mfptr::fptr
int(tclass::* fptr)(std::vector< std::string > &cstr, bool itive_com)
The pointer to the member function.
Definition: cli.h:123
o2scl::cli::cmd_name
std::string cmd_name
The name of the command.
Definition: cli.h:494
o2scl::cli::parameter_double::parse_strings
bool parse_strings
If true, use value_spec() to convert strings to doubles.
Definition: cli.h:313
o2scl::dtos
std::string dtos(const fp_t &x, int prec=6, bool auto_prec=false)
Convert a double to a string.
Definition: string_conv.h:77
o2scl::comm_option_fptr::comm_option_fptr
comm_option_fptr(int(*fp)(std::vector< std::string > &, bool))
Create from a member function pointer from the specified class.
Definition: cli.h:66
o2scl::btos
std::string btos(bool b)
Convert a boolean value to a string.
o2scl::cli::buf
char buf[300]
Storage for getline.
Definition: cli.h:390
o2scl::cmd_line_arg
A command-line argument for o2scl::cli.
Definition: cli.h:183
o2scl::comm_option_s::lng
std::string lng
Long option (must be specified and must be unique)
Definition: cli.h:160
o2scl::cmd_line_arg::is_valid
bool is_valid
Is a properly formatted option.
Definition: cli.h:189
o2scl::cli::get_alias
std::string get_alias(std::string alias)
Set an alias alias for the string str.
o2scl::cli::parameter::get
virtual std::string get()=0
Convert to string.
o2scl::exc_efailed
@ exc_efailed
generic failure
Definition: err_hnd.h:61
o2scl::comm_option_fptr::operator()
virtual int operator()(std::vector< std::string > &cstr, bool itive_com)
The basic function called by o2scl::cli.
Definition: cli.h:73
o2scl::cli::par_t
std::map< std::string, parameter *, std::greater< std::string > >::iterator par_t
List iterator.
Definition: cli.h:376
o2scl::cli::process_args
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.
o2scl::stoi
int stoi(std::string s)
Convert a string to an integer.
o2scl::comm_option_mfptr::tptr
tclass * tptr
The pointer to the class.
Definition: cli.h:126
o2scl::comm_option_s::func
comm_option_funct * func
The pointer to the function to be called (or 0 for no function)
Definition: cli.h:172
o2scl::cli::is_valid_option
bool is_valid_option(std::string str)
Return true if str is a valid option.
o2scl::comm_option_s::help
std::string help
The help description.
Definition: cli.h:170
o2scl::cli::apply_aliases
int apply_aliases(std::vector< std::string > &sv, size_t istart, bool debug=false)
Replace all occurences of sold with snew in sv.
o2scl
The main O<span style='position: relative; top: 0.3em; font-size: 0.8em'>2</span>scl O$_2$scl names...
Definition: anneal.h:42
o2scl::cli::parameter_bool::set
virtual int set(std::string s)
Set from string.
Definition: cli.h:286
o2scl::comm_option_funct
Base for o2scl::cli command function.
Definition: cli.h:47
o2scl::cmd_line_arg::arg
std::string arg
The argument.
Definition: cli.h:185
o2scl::cli::parameter_bool::b
bool * b
Parameter.
Definition: cli.h:283
o2scl::cli::parameter_size_t::set
virtual int set(std::string st)
Set from string.
Definition: cli.h:359
o2scl::cli::sync_verbose
bool sync_verbose
If true, then sync cli::verbose, with a parameter of the same name.
Definition: cli.h:480
o2scl::cli::desc
std::string desc
A one- or two-line description (default is empty string)
Definition: cli.h:491
o2scl::cli::string_equal_dash
bool string_equal_dash(std::string s1, std::string s2)
Compare two strings, treating dashes and underscores as equivalent.
o2scl::cli::parameter_string::get
virtual std::string get()
Convert to string.
Definition: cli.h:269
o2scl::cli::set_param_help
int set_param_help(std::string param, std::string help)
Set one-line help text for a parameter named param.
o2scl::cli::parameter_int::get
virtual std::string get()
Convert to string.
Definition: cli.h:342
o2scl::cli::tilde_string
std::string tilde_string
String to replace tildes with.
Definition: cli.h:440
o2scl::comm_option_s::parm_desc
std::string parm_desc
Description of parameters.
Definition: cli.h:168
o2scl::cli::parameter_bool
String parameter for o2scl::cli.
Definition: cli.h:276
o2scl::cli::parameter_string
String parameter for o2scl::cli.
Definition: cli.h:253
o2scl::cli::call_args
int call_args(std::vector< cmd_line_arg > &ca, int debug=0)
Call functions corresponding to command-line args.
o2scl::cli::set_comm_option
int set_comm_option(comm_option_s &ic)
Add a new command.
o2scl::cli::gnu_intro
bool gnu_intro
If true, output the usual GNU intro when run_interactive() is called (default true).
Definition: cli.h:448
o2scl::cli::addl_help_cmd
std::string addl_help_cmd
Additional help text for interactive mode (default is empty string)
Definition: cli.h:497
o2scl::cli::parameter_bool::get
virtual std::string get()
Convert to string.
Definition: cli.h:292
o2scl::comm_option_s::min_parms
int min_parms
Minimum number of parameters (0 for none, -1 for variable)
Definition: cli.h:164
o2scl::cli::par_list
std::map< std::string, parameter *, std::less< std::string > > par_list
Parameter list.
Definition: cli.h:373
o2scl::cli::set_verbose
int set_verbose(int v)
Set verbosity.
o2scl::cli::parameter_int::i
int * i
Parameter.
Definition: cli.h:333
o2scl::comm_option_mfptr::comm_option_mfptr
comm_option_mfptr(const comm_option_mfptr &f)
Copy constructor.
Definition: cli.h:129
o2scl::exc_einval
@ exc_einval
invalid argument supplied by user
Definition: err_hnd.h:59
o2scl::cli::set_alias
int set_alias(std::string alias, std::string str)
Set an alias alias for the string str.
o2scl::cli::parameter_string::set
virtual int set(std::string s)
Set from string.
Definition: cli.h:263
o2scl::comm_option_funct::operator()
virtual int operator()(std::vector< std::string > &cstr, bool itive_com)=0
The basic function called by o2scl::cli.
o2scl::comm_option_fptr::operator=
comm_option_fptr & operator=(const comm_option_fptr &f)
Copy constructor.
Definition: cli.h:90
o2scl::comm_option_s::type
int type
Type: command-line parameter, command, or both.
Definition: cli.h:174
o2scl::cli::parameter_size_t::s
size_t * s
Parameter.
Definition: cli.h:356
o2scl::cli::set_function
int set_function(comm_option_funct &usf)
Function to call when a set command is issued.
Definition: cli.h:451
o2scl::cli::parameter_int
Integer parameter for o2scl::cli.
Definition: cli.h:326
o2scl::cmd_line_arg::cop
comm_option_s * cop
A pointer to the appropriate option (0, unless it's an option)
Definition: cli.h:193
o2scl::cli::parameter_size_t::get
virtual std::string get()
Convert to string.
Definition: cli.h:364
o2scl::comm_option_s
Command for interactive mode in o2scl::cli.
Definition: cli.h:155
o2scl::cli::parameter_double::set
virtual int set(std::string s)
Set from string.
o2scl::cli
Configurable command-line interface.
Definition: cli.h:230
o2scl::cli::remove_comm_option
void remove_comm_option(std::string cmd)
Remove a command with long name cmd.
o2scl::cli::parameter_double
Double parameter for o2scl::cli.
Definition: cli.h:299
o2scl::comm_option_mfptr::operator()
virtual int operator()(std::vector< std::string > &cstr, bool itive_com)
The basic function called by o2scl::cli.
Definition: cli.h:114
o2scl::comm_option_fptr::fptr
int(* fptr)(std::vector< std::string > &cstr, bool itive_com)
The pointer to the member function.
Definition: cli.h:82
o2scl::cli::process_args_str
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.
o2scl::cli::parameter
Parameter for o2scl::cli.
Definition: cli.h:235
o2scl::stoszt_nothrow
int stoszt_nothrow(std::string s, size_t &result)
Convert a string to a size_t without throwing an exception.
o2scl::comm_option_mfptr
Member function pointer for o2scl::cli command function.
Definition: cli.h:100
o2scl::cli::parameter_int::set
virtual int set(std::string s)
Set from string.
Definition: cli.h:336
o2scl::cli::parameter_double::d
double * d
Parameter.
Definition: cli.h:310
o2scl::itos
std::string itos(int x)
Convert an integer to a string.
o2scl::comm_option_s::shrt
char shrt
Short option ('\0' for none, must be unique if present)
Definition: cli.h:158
o2scl::cli::parameter_double::get
virtual std::string get()
Convert to string.
Definition: cli.h:319
o2scl::cli::prompt
std::string prompt
The prompt (default "> ")
Definition: cli.h:488
o2scl::cli::run_auto
int run_auto(int argc, char *argv[], int debug=0)
Automatically parse arguments to main and call interactive mode if required.
O2SCL_ERR
#define O2SCL_ERR(d, n)
Set an error with message d and code n.
Definition: err_hnd.h:273
o2scl::cli::run_interactive
int run_interactive()
Run the interactive mode.
o2scl::cli::clist
std::vector< comm_option_s > clist
List of commands.
Definition: cli.h:396
o2scl::cli::parameter_string::str
std::string * str
Parameter.
Definition: cli.h:260
o2scl::cli::verbose
int verbose
Control screen output.
Definition: cli.h:387
o2scl::cli::output_param_list
int output_param_list()
Output the parameter list.
o2scl::comm_option_mfptr::comm_option_mfptr
comm_option_mfptr(tclass *tp, int(tclass::*fp)(std::vector< std::string > &, bool))
Create from a member function pointer from the specified class.
Definition: cli.h:105
o2scl::comm_option_s::max_parms
int max_parms
Maximum number of parameters (0 for none, -1 for variable)
Definition: cli.h:166
o2scl::cli::user_set_func
comm_option_funct * user_set_func
Storage for the function to call after setting a parameter.
Definition: cli.h:393
o2scl::cmd_line_arg::parms
std::vector< std::string > parms
List of parameters (empty, unless it's an option)
Definition: cli.h:191
o2scl::cmd_line_arg::is_option
bool is_option
Is an option?
Definition: cli.h:187
o2scl::cli::set_comm_option_vec
int set_comm_option_vec(size_t list_size, vec_t &option_list)
Add a vector containing new commands/options.
Definition: cli.h:522
o2scl::cli::shell_cmd_allowed
bool shell_cmd_allowed
If true, allow the user to use ! to execute a shell command (default true)
Definition: cli.h:485
o2scl::cli::addl_help_cli
std::string addl_help_cli
Additional help text for command-line (default is empty string)
Definition: cli.h:500
o2scl::stob
bool stob(std::string s, bool err_on_fail=true)
Convert a string to a boolean value.
o2scl::comm_option_s::desc
std::string desc
Description for help.
Definition: cli.h:162
o2scl::szttos
std::string szttos(size_t x)
Convert a size_t to a string.
o2scl::comm_option_fptr
Function pointer for o2scl::cli command function.
Definition: cli.h:61
o2scl::comm_option_mfptr::operator=
comm_option_mfptr & operator=(const comm_option_mfptr &f)
Copy constructor.
Definition: cli.h:135
o2scl::cli::parameter::help
std::string help
Help description.
Definition: cli.h:242
o2scl::cli::process_args_c
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.
o2scl::cli::parameter::set
virtual int set(std::string s)=0
Set from string.
o2scl::cli::cli_gets
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).