source: trunk/yat/OptionHelp.cc @ 1336

Last change on this file since 1336 was 1336, checked in by Peter Johansson, 12 years ago

latest yat

  • Property svn:eol-style set to native
File size: 1.8 KB
Line 
1// $Id: OptionHelp.cc 2384 2010-12-22 14:03:36Z peter $
2
3/*
4  Copyright (C) 2007, 2008 Jari Häkkinen, Peter Johansson
5  Copyright (C) 2009, 2010 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 "OptionHelp.h"
24#include "CommandLine.h"
25
26#include <cstdlib>
27#include <iostream>
28#include <string>
29
30namespace theplu {
31namespace yat {
32namespace utility {
33
34
35  OptionHelp::OptionHelp(CommandLine& cmd, std::string flag, 
36                         std::string desc)
37    : OptionSwitch(cmd, flag, desc, false), synopsis_("")
38  {
39  }
40
41
42  void OptionHelp::do_parse2(std::vector<std::string>::iterator first, 
43                               std::vector<std::string>::iterator last)
44  {
45    if (usage_.empty()) 
46      std::cout << "Usage: " << cmd().program_name() << " [OPTION]...\n\n";
47    else
48      std::cout << usage_ << "\n"; 
49    std::cout << synopsis_ << "\n";
50    std::cout << cmd() << "\n"; 
51    std::cout << post_cmd_;
52    exit(EXIT_SUCCESS);
53  }
54
55
56  std::string& OptionHelp::post_arguments(void)
57  {
58    return post_cmd_;
59  }
60
61
62  std::string& OptionHelp::synopsis(void)
63  {
64    return synopsis_;
65  }
66
67  std::string& OptionHelp::usage(void)
68  {
69    return usage_;
70  }
71
72}}} // of namespace utility, yat, and theplu
Note: See TracBrowser for help on using the repository browser.