981 |
22 Oct 07 |
peter |
// $Id$ |
981 |
22 Oct 07 |
peter |
2 |
|
981 |
22 Oct 07 |
peter |
3 |
/* |
4359 |
23 Aug 23 |
peter |
Copyright (C) 2007 Peter Johansson |
4359 |
23 Aug 23 |
peter |
Copyright (C) 2008 Jari Häkkinen, Peter Johansson |
4359 |
23 Aug 23 |
peter |
Copyright (C) 2009, 2010, 2012 Peter Johansson |
981 |
22 Oct 07 |
peter |
7 |
|
1437 |
25 Aug 08 |
peter |
This file is part of the yat library, http://dev.thep.lu.se/yat |
981 |
22 Oct 07 |
peter |
9 |
|
981 |
22 Oct 07 |
peter |
The yat library is free software; you can redistribute it and/or |
981 |
22 Oct 07 |
peter |
modify it under the terms of the GNU General Public License as |
1486 |
09 Sep 08 |
jari |
published by the Free Software Foundation; either version 3 of the |
981 |
22 Oct 07 |
peter |
License, or (at your option) any later version. |
981 |
22 Oct 07 |
peter |
14 |
|
981 |
22 Oct 07 |
peter |
The yat library is distributed in the hope that it will be useful, |
981 |
22 Oct 07 |
peter |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
981 |
22 Oct 07 |
peter |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
981 |
22 Oct 07 |
peter |
General Public License for more details. |
981 |
22 Oct 07 |
peter |
19 |
|
981 |
22 Oct 07 |
peter |
You should have received a copy of the GNU General Public License |
1487 |
10 Sep 08 |
jari |
along with yat. If not, see <http://www.gnu.org/licenses/>. |
981 |
22 Oct 07 |
peter |
22 |
*/ |
981 |
22 Oct 07 |
peter |
23 |
|
2881 |
18 Nov 12 |
peter |
24 |
#include <config.h> |
2881 |
18 Nov 12 |
peter |
25 |
|
981 |
22 Oct 07 |
peter |
26 |
#include "OptionHelp.h" |
981 |
22 Oct 07 |
peter |
27 |
#include "CommandLine.h" |
981 |
22 Oct 07 |
peter |
28 |
|
2055 |
08 Sep 09 |
peter |
29 |
#include <cstdlib> |
2046 |
02 Sep 09 |
peter |
30 |
#include <iostream> |
981 |
22 Oct 07 |
peter |
31 |
#include <string> |
981 |
22 Oct 07 |
peter |
32 |
|
981 |
22 Oct 07 |
peter |
33 |
namespace theplu { |
981 |
22 Oct 07 |
peter |
34 |
namespace yat { |
981 |
22 Oct 07 |
peter |
35 |
namespace utility { |
981 |
22 Oct 07 |
peter |
36 |
|
981 |
22 Oct 07 |
peter |
37 |
|
4200 |
19 Aug 22 |
peter |
38 |
OptionHelp::OptionHelp(CommandLine& cmd, std::string flag, |
981 |
22 Oct 07 |
peter |
39 |
std::string desc) |
981 |
22 Oct 07 |
peter |
40 |
: OptionSwitch(cmd, flag, desc, false), synopsis_("") |
981 |
22 Oct 07 |
peter |
41 |
{ |
981 |
22 Oct 07 |
peter |
42 |
} |
981 |
22 Oct 07 |
peter |
43 |
|
981 |
22 Oct 07 |
peter |
44 |
|
4200 |
19 Aug 22 |
peter |
45 |
void OptionHelp::do_parse2(std::vector<std::string>::iterator first, |
981 |
22 Oct 07 |
peter |
46 |
std::vector<std::string>::iterator last) |
981 |
22 Oct 07 |
peter |
47 |
{ |
4200 |
19 Aug 22 |
peter |
48 |
if (usage_.empty()) |
985 |
22 Oct 07 |
peter |
49 |
std::cout << "Usage: " << cmd().program_name() << " [OPTION]...\n\n"; |
985 |
22 Oct 07 |
peter |
50 |
else |
4200 |
19 Aug 22 |
peter |
51 |
std::cout << usage_ << "\n"; |
985 |
22 Oct 07 |
peter |
52 |
std::cout << synopsis_ << "\n"; |
4200 |
19 Aug 22 |
peter |
53 |
std::cout << cmd() << "\n"; |
981 |
22 Oct 07 |
peter |
54 |
std::cout << post_cmd_; |
2246 |
22 Apr 10 |
peter |
55 |
exit(EXIT_SUCCESS); |
981 |
22 Oct 07 |
peter |
56 |
} |
981 |
22 Oct 07 |
peter |
57 |
|
981 |
22 Oct 07 |
peter |
58 |
|
984 |
22 Oct 07 |
peter |
59 |
std::string& OptionHelp::post_arguments(void) |
984 |
22 Oct 07 |
peter |
60 |
{ |
984 |
22 Oct 07 |
peter |
61 |
return post_cmd_; |
984 |
22 Oct 07 |
peter |
62 |
} |
984 |
22 Oct 07 |
peter |
63 |
|
984 |
22 Oct 07 |
peter |
64 |
|
984 |
22 Oct 07 |
peter |
65 |
std::string& OptionHelp::synopsis(void) |
984 |
22 Oct 07 |
peter |
66 |
{ |
984 |
22 Oct 07 |
peter |
67 |
return synopsis_; |
984 |
22 Oct 07 |
peter |
68 |
} |
984 |
22 Oct 07 |
peter |
69 |
|
984 |
22 Oct 07 |
peter |
70 |
std::string& OptionHelp::usage(void) |
984 |
22 Oct 07 |
peter |
71 |
{ |
984 |
22 Oct 07 |
peter |
72 |
return usage_; |
984 |
22 Oct 07 |
peter |
73 |
} |
984 |
22 Oct 07 |
peter |
74 |
|
981 |
22 Oct 07 |
peter |
75 |
}}} // of namespace utility, yat, and theplu |