source: trunk/yat/utility/OptionHelp.cc

Last change on this file was 2919, checked in by Peter, 9 years ago

update copyright years

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 1.7 KB
Line 
1// $Id: OptionHelp.cc 2919 2012-12-19 06:54:23Z peter $
2
3/*
4  Copyright (C) 2007, 2008 Jari Häkkinen, Peter Johansson
5  Copyright (C) 2009, 2010, 2012 Peter Johansson
6
7  This file is part of the yat library, http://dev.thep.lu.se/yat
8
9  The yat library is free software; you can redistribute it and/or
10  modify it under the terms of the GNU General Public License as
11  published by the Free Software Foundation; either version 3 of the
12  License, or (at your option) any later version.
13
14  The yat library is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  General Public License for more details.
18
19  You should have received a copy of the GNU General Public License
20  along with yat. If not, see <http://www.gnu.org/licenses/>.
21*/
22
23#include <config.h>
24
25#include "OptionHelp.h"
26#include "CommandLine.h"
27
28#include <cstdlib>
29#include <iostream>
30#include <string>
31
32namespace theplu {
33namespace yat {
34namespace utility {
35
36
37  OptionHelp::OptionHelp(CommandLine& cmd, std::string flag, 
38                         std::string desc)
39    : OptionSwitch(cmd, flag, desc, false), synopsis_("")
40  {
41  }
42
43
44  void OptionHelp::do_parse2(std::vector<std::string>::iterator first, 
45                               std::vector<std::string>::iterator last)
46  {
47    if (usage_.empty()) 
48      std::cout << "Usage: " << cmd().program_name() << " [OPTION]...\n\n";
49    else
50      std::cout << usage_ << "\n"; 
51    std::cout << synopsis_ << "\n";
52    std::cout << cmd() << "\n"; 
53    std::cout << post_cmd_;
54    exit(EXIT_SUCCESS);
55  }
56
57
58  std::string& OptionHelp::post_arguments(void)
59  {
60    return post_cmd_;
61  }
62
63
64  std::string& OptionHelp::synopsis(void)
65  {
66    return synopsis_;
67  }
68
69  std::string& OptionHelp::usage(void)
70  {
71    return usage_;
72  }
73
74}}} // of namespace utility, yat, and theplu
Note: See TracBrowser for help on using the repository browser.