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" << "metadata";
47 QSet
<QString
> validOptionsWithComplement
;
48 validOptionsWithComplement
<< "resume-from" << "max-rev" << "identity-map";
50 QStringList arguments
= argumentList
;
51 arguments
.takeFirst(); // the first one is the executable name; drop it
52 while (!arguments
.isEmpty()) {
53 QString arg
= arguments
.takeFirst();
59 if (arg
.startsWith("--"))
60 arg
= arg
.mid(1); // drop double dashes to single
62 if (arg
.startsWith("-no-")) {
65 } else if (!arg
.startsWith("-")) {
67 arguments
.prepend(arg
);
69 } else { // starts with "-"
73 if (arg
.contains('=') && complement
.isEmpty()) {
74 int pos
= arg
.indexOf('=');
75 complement
= arg
.mid(pos
+ 1);
79 if (validOptionsWithComplement
.contains(arg
)) {
80 if (arguments
.isEmpty()) {
81 fprintf(stderr
, "Option -%s requires an argument\n", qPrintable(arg
));
85 if (options
.contains(arg
)) {
86 fprintf(stderr
, "Option -%s given more than once\n", qPrintable(arg
));
90 if (!complement
.isEmpty())
91 options
[arg
] = complement
;
92 else if (!arguments
.isEmpty())
93 options
[arg
] = arguments
.takeFirst();
95 fprintf(stderr
, "Option -%s requires an argument\n", qPrintable(arg
));
99 } else if (validOptions
.contains(arg
)) {
100 if (switches
.contains(arg
)) {
101 fprintf(stderr
, "Option -%s given more than once\n", qPrintable(arg
));
105 switches
[arg
] = !(complement
== "no");
107 if (complement
== "no")
108 fprintf(stderr
, "Invalid option: -no-%s\n", qPrintable(arg
));
110 fprintf(stderr
, "Invalid option: -%s\n", qPrintable(arg
));
115 if (switches
.value("help")) {
118 } else if (arguments
.count() < 2) {
123 ruleFile
= arguments
.takeFirst();
124 pathToRepository
= arguments
.takeFirst();