examples/command_line.cpp
Go to the documentation of this file.
1 
9 /*****************************************************************************
10 ** Includes
11 *****************************************************************************/
12 
13 #include <iostream>
14 #include <string>
15 #include "../../include/ecl/command_line.hpp"
16 
17 /*****************************************************************************
18 ** Using
19 *****************************************************************************/
20 
21 using std::cout;
22 using std::cerr;
23 using std::endl;
24 using std::string;
25 using ecl::CmdLine;
26 using ecl::SwitchArg;
27 using ecl::ValueArg;
29 using ecl::ArgException;
30 
31 /*****************************************************************************
32 ** Main
33 *****************************************************************************/
34 
35 int main(int argc, char** argv) {
36 
37  int test(0);
38  bool debug(false);
39  string nolabel;
40 
41  std::cout << std::endl;
42  std::cout << "***********************************************************" << std::endl;
43  std::cout << " Command Line Parsing" << std::endl;
44  std::cout << "***********************************************************" << std::endl;
45  std::cout << std::endl;
46 
47  try {
48  // Supply a program description, argument separator (optional) and version number (optional).
49  CmdLine cmd("This is a test program to test the command line parsing facilities provided by TCLAP.");
50 // CmdLine cmd("This is a test program to test the command line parsing facilities provided by TCLAP.", ' ', "0.01");
51 
52  // Add a boolean (flag, name, description), sets the default state to false unless it is found on the command line.
53  SwitchArg debugSwitch("d","debug","Enable debugging.");
54  // Add a boolean (flag, name, description, default)
55  // SwitchArg debug("d","debug","Enable debugging.", false);
56  cmd.add(debugSwitch);
57 
58  // Add an int (flag,name,description,compulsory flag?,default value,help description of the type")
59  ValueArg<int> intArg("i","integer","An integer argument for testing.",false,5,"integer");
60  cmd.add(intArg);
61 
62  // (one word argument name, long description, req/not req, default value, type)
63  UnlabeledValueArg<string> nolabelArg( "echo", "An unlabeled argument", false, "dude", "string" );
64  cmd.add(nolabelArg);
65 
66  /*********************
67  ** Parse
68  **********************/
69  cmd.parse(argc,argv);
70  debug = debugSwitch.getValue();
71  test = intArg.getValue();
72  nolabel = nolabelArg.getValue();
73 
74  } catch ( ArgException &e )
75  {
76  cerr << "error: " << e.error() << " for arg " << e.argId() << endl;
77  }
78 
79  cout << "Test Integer: " << test << endl;
80  if ( debug ) {
81  cout << "Debug Switch (bool): true" << endl;
82  } else {
83  cout << "Debug Switch (bool): false" << endl;
84  }
85  std::cout << "Echoing unlabelled arg: " << nolabel << std::endl;
86  std::cout << std::endl;
87 
88  return 0;
89 }
90 
91 
92 
int main(int argc, char **argv)
void add(Arg &a)
Definition: cmd_line.hpp:349
Defines the exception that is thrown whenever a command line is created and parsed.
Manages the command line parsing object.
Definition: cmd_line.hpp:49
std::string argId() const
std::string error() const
void parse(int argc, char **argv)
Definition: cmd_line.hpp:368


ecl_command_line
Author(s): Daniel Stonier
autogenerated on Mon Jun 10 2019 13:08:08