1 | #ifndef _theplu_yat_utility_option_help_ |
---|
2 | #define _theplu_yat_utility_option_help_ |
---|
3 | |
---|
4 | // $Id: OptionHelp.h 1486 2008-09-09 21:17:19Z jari $ |
---|
5 | |
---|
6 | /* |
---|
7 | Copyright (C) 2007 Jari Häkkinen, Peter Johansson |
---|
8 | Copyright (C) 2008 Peter Johansson |
---|
9 | |
---|
10 | This file is part of the yat library, http://dev.thep.lu.se/yat |
---|
11 | |
---|
12 | The yat library is free software; you can redistribute it and/or |
---|
13 | modify it under the terms of the GNU General Public License as |
---|
14 | published by the Free Software Foundation; either version 3 of the |
---|
15 | License, or (at your option) any later version. |
---|
16 | |
---|
17 | The yat library is distributed in the hope that it will be useful, |
---|
18 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
19 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
20 | General Public License for more details. |
---|
21 | |
---|
22 | You should have received a copy of the GNU General Public License |
---|
23 | along with this program; if not, write to the Free Software |
---|
24 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
---|
25 | 02111-1307, USA. |
---|
26 | */ |
---|
27 | |
---|
28 | #include "OptionSwitch.h" |
---|
29 | |
---|
30 | #include <string> |
---|
31 | |
---|
32 | namespace theplu { |
---|
33 | namespace yat { |
---|
34 | namespace utility { |
---|
35 | |
---|
36 | class CommandLine; |
---|
37 | /** |
---|
38 | \brief Class for help option |
---|
39 | |
---|
40 | When this option is found in parsing of commandline, it displays |
---|
41 | a help output and exits. A typical output looks like: |
---|
42 | |
---|
43 | \verbatim |
---|
44 | Usage: foo [OPTION]... |
---|
45 | |
---|
46 | SYNOPSIS |
---|
47 | |
---|
48 | Available options are: |
---|
49 | -h, --help display this help and exit |
---|
50 | -v, --verbose explain what is being done |
---|
51 | |
---|
52 | Some extra information explaining something. |
---|
53 | \endverbatim |
---|
54 | |
---|
55 | The output consist of four blocks. The first block can be |
---|
56 | modified with usage(void) function. The second is block is |
---|
57 | typically a one-liner explaining the application and can be |
---|
58 | modified with the synopsis(void) function. The third block |
---|
59 | contain the description of the different options, see |
---|
60 | operator<<(std::ostream&, const CommandLine&) for further |
---|
61 | details. The last block can be modified with post_arguments(void) |
---|
62 | function. |
---|
63 | */ |
---|
64 | class OptionHelp : public OptionSwitch |
---|
65 | { |
---|
66 | public: |
---|
67 | /** |
---|
68 | \brief Constructor |
---|
69 | |
---|
70 | \param cmd Commandline Option is associated with |
---|
71 | \param name string such as "help" for --help, "h" for -h or |
---|
72 | "h,help" (default) for having both short and long option name |
---|
73 | \param desc string used in help display |
---|
74 | */ |
---|
75 | OptionHelp(CommandLine& cmd, std::string name="h,help", |
---|
76 | std::string desc="display this help and exit"); |
---|
77 | |
---|
78 | /** |
---|
79 | Text to be displayed after list of arguments. |
---|
80 | */ |
---|
81 | std::string& post_arguments(void); |
---|
82 | |
---|
83 | /** |
---|
84 | Text to be displayed in help output after usage() |
---|
85 | */ |
---|
86 | std::string& synopsis(void); |
---|
87 | |
---|
88 | /** |
---|
89 | First line to be displayed in help output. Default this string |
---|
90 | is set to "Usage: <program_name> [OPTION]...\n\n" |
---|
91 | */ |
---|
92 | std::string& usage(void); |
---|
93 | |
---|
94 | private: |
---|
95 | std::string usage_; |
---|
96 | std::string synopsis_; |
---|
97 | std::string post_cmd_; |
---|
98 | |
---|
99 | /** |
---|
100 | */ |
---|
101 | void do_parse2(std::vector<std::string>::iterator, |
---|
102 | std::vector<std::string>::iterator); |
---|
103 | |
---|
104 | }; |
---|
105 | |
---|
106 | }}} // of namespace utility, yat, and theplu |
---|
107 | |
---|
108 | #endif |
---|