2 * Copyright (C) 2007 Thiago Macieira <thiago@kde.org>
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #include <QStringList>
26 Options* Options::globalOptions = 0;
37 void Options::showHelp()
39 printf("Usage: svn-all-fast-export configfile path-to-svn\n");
42 void Options::parseArguments(const QStringList &argumentList)
44 QSet<QString> validOptions;
45 validOptions << "help";
47 QHash<QString, QString> optionsWithComplement;
48 optionsWithComplement.insert("resume-from", QString());
49 optionsWithComplement.insert("identity-map", QString());
51 QStringList arguments = argumentList;
52 arguments.takeFirst(); // the first one is the executable name; drop it
53 while (!arguments.isEmpty()) {
54 QString arg = arguments.takeFirst();
60 if (arg.startsWith("--"))
61 arg = arg.mid(1); // drop double dashes to single
63 if (arg.startsWith("-no-")) {
66 } else if (!arg.startsWith("-")) {
69 } else { // starts with "-"
73 if (arg.contains('=') && complement.isEmpty()) {
74 int pos = arg.indexOf('=');
75 complement = arg.mid(pos + 1);
79 if (optionsWithComplement.contains(arg)) {
80 if (arguments.isEmpty()) {
81 fprintf(stderr, "Option -%s requires an argument", qPrintable(arg));
85 QString &setting = optionsWithComplement[arg];
86 if (!setting.isNull()) {
87 fprintf(stderr, "Option -%s given more than once", qPrintable(arg));
91 if (!complement.isEmpty())
93 else if (!arguments.isEmpty())
94 setting = arguments.takeFirst();
96 fprintf(stderr, "Option -%s requires an argument", qPrintable(arg));
100 } else if (validOptions.contains(arg)) {
101 if (switches.contains(arg)) {
102 fprintf(stderr, "Option -%s given more than once", qPrintable(arg));
106 switches[arg] = !(complement == "no");
108 if (complement == "no")
109 fprintf(stderr, "Invalid option: -no-%s", qPrintable(arg));
111 fprintf(stderr, "Invalid option: -%s", qPrintable(arg));
116 if (switches.value("help")) {
119 } else if (arguments.count() < 2) {
124 ruleFile = arguments.takeFirst();
125 pathToRepository = arguments.takeFirst();