1 | // $Id: commandline_test.cc 680 2006-10-11 17:49:03Z jari $ |
---|
2 | |
---|
3 | /* |
---|
4 | Copyright (C) The authors contributing to this file. |
---|
5 | |
---|
6 | This file is part of the yat library, http://lev.thep.lu.se/trac/yat |
---|
7 | |
---|
8 | The yat library is free software; you can redistribute it and/or |
---|
9 | modify it under the terms of the GNU General Public License as |
---|
10 | published by the Free Software Foundation; either version 2 of the |
---|
11 | License, or (at your option) any later version. |
---|
12 | |
---|
13 | The yat library 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 GNU |
---|
16 | General Public License for more details. |
---|
17 | |
---|
18 | You should have received a copy of the GNU General Public License |
---|
19 | along with this program; if not, write to the Free Software |
---|
20 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
---|
21 | 02111-1307, USA. |
---|
22 | */ |
---|
23 | |
---|
24 | #include "yat/utility/CommandLine.h" |
---|
25 | #include "yat/utility/Option.h" |
---|
26 | |
---|
27 | #include <iostream> |
---|
28 | |
---|
29 | using namespace theplu::yat; |
---|
30 | |
---|
31 | int main(const int argc,const char* argv[]) |
---|
32 | { |
---|
33 | bool ok = true; |
---|
34 | |
---|
35 | utility::CommandLine cmd; |
---|
36 | cmd.set_general_description("test program for CommandLine class"); |
---|
37 | cmd.add_parameter('n', utility::Option::int_arg, |
---|
38 | "example of parameter taking an integer"); |
---|
39 | cmd.add_parameter('v',utility::Option::no_arg, "explain what is being done"); |
---|
40 | cmd.add_parameter('t', "target", utility::Option::string_arg); |
---|
41 | cmd.add_parameter("version",utility::Option::no_arg, |
---|
42 | "output version infomation and exit"); |
---|
43 | cmd.set_help(); |
---|
44 | cmd.parse(argc, argv); |
---|
45 | std::string target = cmd.value("target"); |
---|
46 | if (!target.empty()) |
---|
47 | std::cout << "target: " << target << std::endl; |
---|
48 | int n = cmd.value_int("n"); |
---|
49 | if (cmd.present("n")) |
---|
50 | std::cout << "n: " << n << std::endl; |
---|
51 | if (cmd.present("v")) |
---|
52 | std::cout << "verbose" << std::endl; |
---|
53 | |
---|
54 | if (ok) { |
---|
55 | return 0; |
---|
56 | } |
---|
57 | return -1; |
---|
58 | |
---|
59 | } |
---|