Don't allow to unrecord past the branch point
[vng.git] / CommandLineParser.h
blob1b755fea5d2cf29d523d4615b84292ccd3c622d8
1 /*
2 * This file is part of the vng project
3 * Copyright (C) 2008 Thomas Zander <tzander@trolltech.com>
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 3 of the License, or
8 * (at your option) any later version.
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.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 #ifndef COMMANDLINEPARSER_H
20 #define COMMANDLINEPARSER_H
22 #include <QString>
24 struct CommandLineOption {
25 /**
26 * The specification of an option includes the name of the option the user must pass and optional arguments it has.
27 * Example specifications are;
28 * <ol>
29 * <li>"-a, --all" </li>
30 * <li>"--version" </li>
31 * <li>"--type name" </li>
32 * <li>"-f, --format name [suffix] [foo]" </li> </ol>
33 * Number 1 allows the user to either type -a or --all (or /A on Windows) to activate this option.
34 * Number 2 allows the user to type --version to activate this option.
35 * Number 3 requires the user to type a single argument after the option.
36 * Number 4 Allows the user to either use -f or --format, which is followed by a required arguments
37 * and optionally 2 more arguments.
39 const char *specification;
40 /**
41 * A textual description of the option that will be printed when the user asks for help.
43 const char *description;
46 #define CommandLineLastOption { 0, 0 }
48 class CommandLineParser {
49 public:
50 static void init(int argc, char *argv[]);
51 static void addOptionDefinitions(const CommandLineOption *definitions);
52 static void setArgumentDefinition(const char *definition);
53 static CommandLineParser *instance();
55 ~CommandLineParser();
57 void usage(const QString &name, const QString &argumentDescription = QString());
59 /// return the options that the user passed
60 QStringList options() const;
61 /// returns true if the option was found.
62 bool contains(const QString & key) const;
64 /// returns the list of items that are not options, note that the first one is the name of the command called
65 QStringList arguments() const;
67 /// return the list of options that the user passed but we don't have a definition for.
68 QStringList undefinedOptions() const;
70 QString optionArgument(const QString &optionName, const QString &defaultValue = QString()) const;
71 QStringList optionArguments(const QString &optionName) const;
73 QStringList parseErrors() const;
75 private:
76 CommandLineParser(int argc, char **argv);
77 class Private;
78 Private * const d;
79 static CommandLineParser *self;
82 #endif