1 | // $Id: OptionHelp.cc 2055 2009-09-08 18:23:43Z peter $ |
---|
2 | |
---|
3 | /* |
---|
4 | Copyright (C) 2007, 2008 Jari Häkkinen, Peter Johansson |
---|
5 | |
---|
6 | This file is part of the yat library, http://dev.thep.lu.se/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 3 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 yat. If not, see <http://www.gnu.org/licenses/>. |
---|
20 | */ |
---|
21 | |
---|
22 | #include "OptionHelp.h" |
---|
23 | #include "CommandLine.h" |
---|
24 | |
---|
25 | #include <cstdlib> |
---|
26 | #include <iostream> |
---|
27 | #include <string> |
---|
28 | |
---|
29 | namespace theplu { |
---|
30 | namespace yat { |
---|
31 | namespace utility { |
---|
32 | |
---|
33 | |
---|
34 | OptionHelp::OptionHelp(CommandLine& cmd, std::string flag, |
---|
35 | std::string desc) |
---|
36 | : OptionSwitch(cmd, flag, desc, false), synopsis_("") |
---|
37 | { |
---|
38 | } |
---|
39 | |
---|
40 | |
---|
41 | void OptionHelp::do_parse2(std::vector<std::string>::iterator first, |
---|
42 | std::vector<std::string>::iterator last) |
---|
43 | { |
---|
44 | if (usage_.empty()) |
---|
45 | std::cout << "Usage: " << cmd().program_name() << " [OPTION]...\n\n"; |
---|
46 | else |
---|
47 | std::cout << usage_ << "\n"; |
---|
48 | std::cout << synopsis_ << "\n"; |
---|
49 | std::cout << cmd() << "\n"; |
---|
50 | std::cout << post_cmd_; |
---|
51 | exit(0); |
---|
52 | } |
---|
53 | |
---|
54 | |
---|
55 | std::string& OptionHelp::post_arguments(void) |
---|
56 | { |
---|
57 | return post_cmd_; |
---|
58 | } |
---|
59 | |
---|
60 | |
---|
61 | std::string& OptionHelp::synopsis(void) |
---|
62 | { |
---|
63 | return synopsis_; |
---|
64 | } |
---|
65 | |
---|
66 | std::string& OptionHelp::usage(void) |
---|
67 | { |
---|
68 | return usage_; |
---|
69 | } |
---|
70 | |
---|
71 | }}} // of namespace utility, yat, and theplu |
---|