Add a --no-metadata option to suppress the svn info in commit messages.
[svn-all-fast-export.git] / src / options.cpp
blob892b6e10a22fc7e3b4d40409000b143270231e64
1 /*
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/>.
18 #include "options.h"
20 #include <QSet>
21 #include <QStringList>
23 #include <stdio.h>
24 #include <stdlib.h>
26 Options* Options::globalOptions = 0;
28 Options::Options()
30 globalOptions = this;
33 Options::~Options()
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();
54 QString complement;
56 if (arg == "--")
57 break;
59 if (arg.startsWith("--"))
60 arg = arg.mid(1); // drop double dashes to single
62 if (arg.startsWith("-no-")) {
63 complement = "no";
64 arg = arg.mid(4);
65 } else if (!arg.startsWith("-")) {
66 // non-option arg
67 arguments.prepend(arg);
68 break;
69 } else { // starts with "-"
70 arg = arg.mid(1);
73 if (arg.contains('=') && complement.isEmpty()) {
74 int pos = arg.indexOf('=');
75 complement = arg.mid(pos + 1);
76 arg.truncate(pos);
79 if (validOptionsWithComplement.contains(arg)) {
80 if (arguments.isEmpty()) {
81 fprintf(stderr, "Option -%s requires an argument\n", qPrintable(arg));
82 exit(2);
85 if (options.contains(arg)) {
86 fprintf(stderr, "Option -%s given more than once\n", qPrintable(arg));
87 exit(2);
90 if (!complement.isEmpty())
91 options[arg] = complement;
92 else if (!arguments.isEmpty())
93 options[arg] = arguments.takeFirst();
94 else {
95 fprintf(stderr, "Option -%s requires an argument\n", qPrintable(arg));
96 exit(2);
98 continue;
99 } else if (validOptions.contains(arg)) {
100 if (switches.contains(arg)) {
101 fprintf(stderr, "Option -%s given more than once\n", qPrintable(arg));
102 exit(2);
105 switches[arg] = !(complement == "no");
106 } else {
107 if (complement == "no")
108 fprintf(stderr, "Invalid option: -no-%s\n", qPrintable(arg));
109 else
110 fprintf(stderr, "Invalid option: -%s\n", qPrintable(arg));
111 exit(2);
115 if (switches.value("help")) {
116 showHelp();
117 exit(0);
118 } else if (arguments.count() < 2) {
119 showHelp();
120 exit(2);
123 ruleFile = arguments.takeFirst();
124 pathToRepository = arguments.takeFirst();