yat/utility/OptionHelp.h

Code
Comments
Other
Rev Date Author Line
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 4 // $Id$
981 22 Oct 07 peter 5
981 22 Oct 07 peter 6 /*
4359 23 Aug 23 peter 7   Copyright (C) 2007 Peter Johansson
4359 23 Aug 23 peter 8   Copyright (C) 2008 Jari Häkkinen, Peter Johansson
981 22 Oct 07 peter 9
1437 25 Aug 08 peter 10   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 12   The yat library is free software; you can redistribute it and/or
981 22 Oct 07 peter 13   modify it under the terms of the GNU General Public License as
1486 09 Sep 08 jari 14   published by the Free Software Foundation; either version 3 of the
981 22 Oct 07 peter 15   License, or (at your option) any later version.
981 22 Oct 07 peter 16
981 22 Oct 07 peter 17   The yat library is distributed in the hope that it will be useful,
981 22 Oct 07 peter 18   but WITHOUT ANY WARRANTY; without even the implied warranty of
981 22 Oct 07 peter 19   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
981 22 Oct 07 peter 20   General Public License for more details.
981 22 Oct 07 peter 21
981 22 Oct 07 peter 22   You should have received a copy of the GNU General Public License
1487 10 Sep 08 jari 23   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 36      \brief Class for help option
981 22 Oct 07 peter 37
981 22 Oct 07 peter 38      When this option is found in parsing of commandline, it displays
1437 25 Aug 08 peter 39      a help output and exits. A typical output looks like:
1437 25 Aug 08 peter 40
1437 25 Aug 08 peter 41      \verbatim
1437 25 Aug 08 peter 42      Usage: foo [OPTION]...
1437 25 Aug 08 peter 43
1437 25 Aug 08 peter 44      SYNOPSIS
1437 25 Aug 08 peter 45
1437 25 Aug 08 peter 46      Available options are:
1437 25 Aug 08 peter 47      -h, --help      display this help and exit
1437 25 Aug 08 peter 48      -v, --verbose   explain what is being done
1437 25 Aug 08 peter 49
1437 25 Aug 08 peter 50      Some extra information explaining something.
1437 25 Aug 08 peter 51      \endverbatim
1437 25 Aug 08 peter 52
1437 25 Aug 08 peter 53      The output consist of four blocks. The first block can be
1437 25 Aug 08 peter 54      modified with usage(void) function. The second is block is
1437 25 Aug 08 peter 55      typically a one-liner explaining the application and can be
1437 25 Aug 08 peter 56      modified with the synopsis(void) function. The third block
1437 25 Aug 08 peter 57      contain the description of the different options, see
1437 25 Aug 08 peter 58      operator<<(std::ostream&, const CommandLine&) for further
1437 25 Aug 08 peter 59      details. The last block can be modified with post_arguments(void)
1437 25 Aug 08 peter 60      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 66        \brief Constructor
4200 19 Aug 22 peter 67
981 22 Oct 07 peter 68        \param cmd Commandline Option is associated with
981 22 Oct 07 peter 69        \param name string such as "help" for --help, "h" for -h or
981 22 Oct 07 peter 70        "h,help" (default) for having both short and long option name
981 22 Oct 07 peter 71        \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 77        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 82        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 87        First line to be displayed in help output. Default this string
981 22 Oct 07 peter 88        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