source: trunk/test/commandline_test.cc @ 594

Last change on this file since 594 was 594, checked in by Peter, 16 years ago

closes #91 class parsing commandline

File size: 931 bytes
Line 
1// $Id$
2
3#include <c++_tools/utility/CommandLine.h>
4#include <c++_tools/utility/Option.h>
5
6#include <iostream>
7
8using namespace theplu;
9
10int main(const int argc,const char* argv[])
11{
12  bool ok = true;
13
14  utility::CommandLine cmd;
15  cmd.add_parameter("n", utility::Option::int_arg, 
16                    "example of parameter taking an integer");
17  cmd.add_parameter("v",utility::Option::no_arg, "explain what is being done");
18  cmd.add_parameter("t", "target", utility::Option::string_arg);
19  cmd.add_parameter("version",utility::Option::no_arg, 
20                    "output version infomation and exit");
21  cmd.set_help();
22  cmd.parse(argc, argv);
23  std::string target = cmd.value("target");
24  if (!target.empty())
25    std::cout << "target: " << target << std::endl;
26  int n = cmd.value_int("n");
27  if (cmd.present("n"))
28    std::cout << "n: " << n << std::endl;
29  if (cmd.present("v"))
30    std::cout << "verbose" << std::endl;
31
32  if (ok) {
33    return 0;
34  }
35  return -1;
36
37}
Note: See TracBrowser for help on using the repository browser.