981 |
22 Oct 07 |
peter |
1 |
#ifndef _theplu_yat_utility_option_help_ |
981 |
22 Oct 07 |
peter |
2 |
#define _theplu_yat_utility_option_help_ |
981 |
22 Oct 07 |
peter |
3 |
|
981 |
22 Oct 07 |
peter |
// $Id$ |
981 |
22 Oct 07 |
peter |
5 |
|
981 |
22 Oct 07 |
peter |
6 |
/* |
4359 |
23 Aug 23 |
peter |
Copyright (C) 2007 Peter Johansson |
4359 |
23 Aug 23 |
peter |
Copyright (C) 2008 Jari Häkkinen, Peter Johansson |
981 |
22 Oct 07 |
peter |
9 |
|
1437 |
25 Aug 08 |
peter |
This file is part of the yat library, http://dev.thep.lu.se/yat |
981 |
22 Oct 07 |
peter |
11 |
|
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 |
16 |
|
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 |
21 |
|
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 |
24 |
*/ |
981 |
22 Oct 07 |
peter |
25 |
|
981 |
22 Oct 07 |
peter |
26 |
#include "OptionSwitch.h" |
981 |
22 Oct 07 |
peter |
27 |
|
981 |
22 Oct 07 |
peter |
28 |
#include <string> |
981 |
22 Oct 07 |
peter |
29 |
|
981 |
22 Oct 07 |
peter |
30 |
namespace theplu { |
981 |
22 Oct 07 |
peter |
31 |
namespace yat { |
981 |
22 Oct 07 |
peter |
32 |
namespace utility { |
981 |
22 Oct 07 |
peter |
33 |
|
981 |
22 Oct 07 |
peter |
34 |
class CommandLine; |
981 |
22 Oct 07 |
peter |
35 |
/** |
981 |
22 Oct 07 |
peter |
\brief Class for help option |
981 |
22 Oct 07 |
peter |
37 |
|
981 |
22 Oct 07 |
peter |
When this option is found in parsing of commandline, it displays |
1437 |
25 Aug 08 |
peter |
a help output and exits. A typical output looks like: |
1437 |
25 Aug 08 |
peter |
40 |
|
1437 |
25 Aug 08 |
peter |
\verbatim |
1437 |
25 Aug 08 |
peter |
Usage: foo [OPTION]... |
1437 |
25 Aug 08 |
peter |
43 |
|
1437 |
25 Aug 08 |
peter |
SYNOPSIS |
1437 |
25 Aug 08 |
peter |
45 |
|
1437 |
25 Aug 08 |
peter |
Available options are: |
1437 |
25 Aug 08 |
peter |
-h, --help display this help and exit |
1437 |
25 Aug 08 |
peter |
-v, --verbose explain what is being done |
1437 |
25 Aug 08 |
peter |
49 |
|
1437 |
25 Aug 08 |
peter |
Some extra information explaining something. |
1437 |
25 Aug 08 |
peter |
\endverbatim |
1437 |
25 Aug 08 |
peter |
52 |
|
1437 |
25 Aug 08 |
peter |
The output consist of four blocks. The first block can be |
1437 |
25 Aug 08 |
peter |
modified with usage(void) function. The second is block is |
1437 |
25 Aug 08 |
peter |
typically a one-liner explaining the application and can be |
1437 |
25 Aug 08 |
peter |
modified with the synopsis(void) function. The third block |
1437 |
25 Aug 08 |
peter |
contain the description of the different options, see |
1437 |
25 Aug 08 |
peter |
operator<<(std::ostream&, const CommandLine&) for further |
1437 |
25 Aug 08 |
peter |
details. The last block can be modified with post_arguments(void) |
1437 |
25 Aug 08 |
peter |
function. |
981 |
22 Oct 07 |
peter |
61 |
*/ |
981 |
22 Oct 07 |
peter |
62 |
class OptionHelp : public OptionSwitch |
981 |
22 Oct 07 |
peter |
63 |
{ |
981 |
22 Oct 07 |
peter |
64 |
public: |
981 |
22 Oct 07 |
peter |
65 |
/** |
4200 |
19 Aug 22 |
peter |
\brief Constructor |
4200 |
19 Aug 22 |
peter |
67 |
|
981 |
22 Oct 07 |
peter |
\param cmd Commandline Option is associated with |
981 |
22 Oct 07 |
peter |
\param name string such as "help" for --help, "h" for -h or |
981 |
22 Oct 07 |
peter |
"h,help" (default) for having both short and long option name |
981 |
22 Oct 07 |
peter |
\param desc string used in help display |
981 |
22 Oct 07 |
peter |
72 |
*/ |
4200 |
19 Aug 22 |
peter |
73 |
OptionHelp(CommandLine& cmd, std::string name="h,help", |
4200 |
19 Aug 22 |
peter |
74 |
std::string desc="display this help and exit"); |
981 |
22 Oct 07 |
peter |
75 |
|
981 |
22 Oct 07 |
peter |
76 |
/** |
981 |
22 Oct 07 |
peter |
Text to be displayed after list of arguments. |
981 |
22 Oct 07 |
peter |
78 |
*/ |
981 |
22 Oct 07 |
peter |
79 |
std::string& post_arguments(void); |
981 |
22 Oct 07 |
peter |
80 |
|
981 |
22 Oct 07 |
peter |
81 |
/** |
981 |
22 Oct 07 |
peter |
Text to be displayed in help output after usage() |
981 |
22 Oct 07 |
peter |
83 |
*/ |
981 |
22 Oct 07 |
peter |
84 |
std::string& synopsis(void); |
981 |
22 Oct 07 |
peter |
85 |
|
981 |
22 Oct 07 |
peter |
86 |
/** |
981 |
22 Oct 07 |
peter |
First line to be displayed in help output. Default this string |
981 |
22 Oct 07 |
peter |
is set to "Usage: <program_name> [OPTION]...\n\n" |
981 |
22 Oct 07 |
peter |
89 |
*/ |
981 |
22 Oct 07 |
peter |
90 |
std::string& usage(void); |
981 |
22 Oct 07 |
peter |
91 |
|
981 |
22 Oct 07 |
peter |
92 |
private: |
981 |
22 Oct 07 |
peter |
93 |
std::string usage_; |
981 |
22 Oct 07 |
peter |
94 |
std::string synopsis_; |
981 |
22 Oct 07 |
peter |
95 |
std::string post_cmd_; |
981 |
22 Oct 07 |
peter |
96 |
|
981 |
22 Oct 07 |
peter |
97 |
/** |
981 |
22 Oct 07 |
peter |
98 |
*/ |
4200 |
19 Aug 22 |
peter |
99 |
void do_parse2(std::vector<std::string>::iterator, |
981 |
22 Oct 07 |
peter |
100 |
std::vector<std::string>::iterator); |
981 |
22 Oct 07 |
peter |
101 |
|
981 |
22 Oct 07 |
peter |
102 |
}; |
981 |
22 Oct 07 |
peter |
103 |
|
981 |
22 Oct 07 |
peter |
104 |
}}} // of namespace utility, yat, and theplu |
981 |
22 Oct 07 |
peter |
105 |
|
981 |
22 Oct 07 |
peter |
106 |
#endif |