LegacyPeer: kill the dependency to Quassel::buildInfo()
[quassel.git] / src / common / abstractcliparser.h
1 /***************************************************************************
2  *   Copyright (C) 2005-2014 by the Quassel Project                        *
3  *   devel@quassel-irc.org                                                 *
4  *                                                                         *
5  *   This program is free software; you can redistribute it and/or modify  *
6  *   it under the terms of the GNU General Public License as published by  *
7  *   the Free Software Foundation; either version 2 of the License, or     *
8  *   (at your option) version 3.                                           *
9  *                                                                         *
10  *   This program is distributed in the hope that it will be useful,       *
11  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
13  *   GNU General Public License for more details.                          *
14  *                                                                         *
15  *   You should have received a copy of the GNU General Public License     *
16  *   along with this program; if not, write to the                         *
17  *   Free Software Foundation, Inc.,                                       *
18  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
19  ***************************************************************************/
20
21 #ifndef ABSTRACTCLIPARSER_H
22 #define ABSTRACTCLIPARSER_H
23
24 #include <QStringList>
25
26 class AbstractCliParser
27 {
28 public:
29     virtual bool init(const QStringList &arguments = QStringList()) = 0;
30
31     virtual QString value(const QString &longName) = 0;
32     virtual bool isSet(const QString &longName) = 0;
33     inline void addSwitch(const QString &longName, const char shortName = 0, const QString &help = QString())
34     {
35         addArgument(longName, CliParserArg(CliParserArg::CliArgSwitch, shortName, help));
36     }
37
38
39     inline void addOption(const QString &longName, const char shortName = 0, const QString &help = QString(), const QString &def = QString())
40     {
41         addArgument(longName, CliParserArg(CliParserArg::CliArgOption, shortName, help, def));
42     }
43
44
45     virtual void usage() = 0;
46
47     virtual ~AbstractCliParser() {};
48
49 protected:
50     struct CliParserArg {
51         enum CliArgType {
52             CliArgInvalid,
53             CliArgSwitch,
54             CliArgOption
55         };
56
57         CliParserArg(const CliArgType _type = CliArgInvalid, const char _shortName = 0, const QString _help = QString(), const QString _def = QString())
58             : type(_type),
59             shortName(_shortName),
60             help(_help),
61             def(_def),
62             value(QString()),
63             boolValue(false) {};
64
65         CliArgType type;
66         char shortName;
67         QString help;
68         QString def;
69         QString value;
70         bool boolValue;
71     };
72
73     virtual void addArgument(const QString &longName, const CliParserArg &arg) = 0;
74 };
75
76
77 #endif