2 * This file is part of the vng project
3 * Copyright (C) 2008 Thomas Zander <tzander@trolltech.com>
4 * Copyright (C) 2002-2005 David Roundy
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 #include "VngCommandLine.h"
20 #include "CommandLineParser.h"
24 #include "commands/Add.h"
25 #include "commands/Branches.h"
26 #include "commands/Changes.h"
27 #include "commands/Dist.h"
28 #include "commands/Initialize.h"
29 #include "commands/Move.h"
30 #include "commands/Push.h"
31 #include "commands/Record.h"
32 #include "commands/Remove.h"
33 #include "commands/Revert.h"
34 #include "commands/UnRecord.h"
35 #include "commands/UnRevert.h"
36 #include "commands/WhatsNew.h"
38 #include <QTextStream>
40 #define VERSION "vng version 0.26 (>2008-05-16)"
42 VngCommandLine::VngCommandLine(int argc
, char **argv
)
43 : QCoreApplication(argc
, argv
)
46 m_command
= QString(argv
[1]);
47 if (m_command
== "help" && argc
> 2) { // 'help foo' -> 'foo -h'
49 argv
[2] = new char[3];// this is a memory leak, do we care?
53 m_command
= QString(argv
[1]);
56 CommandLineParser::init(argc
, argv
);
59 VngCommandLine::~VngCommandLine()
61 delete CommandLineParser::instance();
64 int VngCommandLine::run()
66 if (m_command
== "--extended-help") {
70 if (m_command
== "--version" || m_command
== "-v"
75 QTextStream
out(stdout
);
76 out
<< VERSION
<< endl
;
79 if (m_command
.isEmpty()) {
84 if (m_command
== "--commands") { // for commandline completion.
85 Configuration
config("");
86 QTextStream
out(stdout
);
87 out
<< "help" << endl
;
88 out
<< "initialize" << endl
;
89 out
<< "--help" << endl
;
90 out
<< "--version" << endl
;
91 out
<< "--extended--help" << endl
;
92 if (QDir(config
.repository().absolutePath() + "/.git").exists()) {
94 out
<< "branches" << endl
;
95 out
<< "changes" << endl
;
96 out
<< "dist" << endl
;
98 out
<< "move" << endl
;
100 out
<< "push" << endl
;
101 out
<< "record" << endl
;
102 out
<< "remove" << endl
;
103 out
<< "revert" << endl
;
105 out
<< "unrecord" << endl
;
106 out
<< "unrevert" << endl
;
107 out
<< "whatsnew" << endl
;
112 // autoComplete command
113 QStringList commands
;
114 // keep this list sorted in the sourcecode. In vim just select the lines and do a :'<,'>!sort
116 commands
<< "branches";
117 commands
<< "changes";
120 commands
<< "initialize";
125 commands
<< "record";
126 commands
<< "remove";
127 commands
<< "revert";
129 commands
<< "unrecord";
130 commands
<< "unrevert";
131 commands
<< "whatsnew";
134 foreach(QString s
, commands
) {
135 if (m_command
== s
) { // perfect match
139 if (! command
.isEmpty()) {
140 if (s
.startsWith(m_command
)) {
141 QTextStream
out(stdout
);
142 out
<< "vng failed: " << "Ambiguous command..." << endl
;
146 break; // found best match.
148 if (s
.startsWith(m_command
)) {
153 if (command
.isEmpty()) {
154 if (! m_command
.isEmpty()) {
155 QTextStream
out(stdout
);
156 out
<< "vng failed: " << "Invalid command `" << m_command
<< "'\n\n";
163 AbstractCommand
*ac
= 0;
164 if (m_command
== "whatsnew")
166 else if (m_command
== "add")
168 else if (m_command
== "branches")
170 else if (m_command
== "changes" || m_command
== "log")
172 else if (m_command
== "initialize")
173 ac
= new Initialize();
174 else if (m_command
== "move" || m_command
== "mv")
176 else if (m_command
== "push")
178 else if (m_command
== "remove" || m_command
== "rm")
180 else if (m_command
== "revert")
182 else if (m_command
== "unrecord")
184 else if (m_command
== "unrevert")
186 else if (m_command
== "dist")
188 else if (command
== "help") {
192 else if (m_command
== "record")
199 void VngCommandLine::printHelp()
201 QTextStream
out(stdout
);
202 out
<< "Usage: vng COMMAND ...\n\n" << VERSION
<< endl
;
203 out
<< "Commands:" << endl
;
204 out
<< " help Display help for vng or a single commands." << endl
;
205 out
<< "Changing and querying the working copy:" << endl
;
206 Configuration
config("");
207 out
<< " add Add one or more new files or directories." << endl
;
208 out
<< " remove Remove one or more files or directories from the repository." << endl
;
209 out
<< " mv Move/rename one or more files or directories." << endl
;
210 out
<< " revert Revert to the recorded version (safe the first time only)." << endl
;
211 out
<< " unrevert Undo the last revert (may fail if changes after the revert)." << endl
;
212 out
<< " whatsnew Display unrecorded changes in the working copy." << endl
;
213 out
<< "Copying changes between the working copy and the repository:" << endl
;
214 out
<< " record Save changes in the working copy to the repository as a patch." << endl
;
215 out
<< " unrecord Remove recorded patches without changing the working copy." << endl
;
216 out
<< "Copying patches between repositories with working copy update:" << endl
;
217 out
<< " push Copy and apply patches from this repository to another one." << endl
;
218 out
<< "Querying the repository:" << endl
;
219 // out << " diff Create a diff between two versions of the repository." << endl;
220 // out << " branches " << endl;
221 out
<< " dist Create a distribution tarball." << endl
;
222 out
<< " changes Gives a changelog-style summary of the repository history." << endl
;
223 out
<< "Administrating repositories:" << endl
;
224 out
<< " initialize Initialize a new source tree as a vng repository." << endl
;
226 out
<< "Use 'vng --extended-help' for more detailed help." << endl
;
227 out
<< "Use 'vng COMMAND --help' for help on a single command." << endl
;
228 out
<< "Use 'vng --version' to see the vng version number." << endl
;
231 void VngCommandLine::printExtendedHelp()
233 QTextStream
out(stdout
);
234 out
<< VERSION
<< endl
;
235 out
<< "Usage: vng COMMAND ...\n\n";
236 out
<< "Extended Help:\n\n";
237 out
<< "A vng repository consists of:\n\n";
238 out
<< " - a set of PATCHES\n";
239 out
<< " - a WORKING directory\n\n";
240 out
<< "Here is a description of which of these components is altered by each\n";
241 out
<< "command, and how it is used or altered:\n\n";
242 out
<< " whatsnew Show the differences between WORKING and the \"recorded\"\n";
243 out
<< " version, that is, the result of applying all PATCHES in the\n";
244 out
<< " repository. This difference, we will call LOCAL CHANGES.\n\n";
245 out
<< " record Add a patch to PATCHES representing the LOCAL CHANGES.\n\n";
246 out
<< " unrecord Delete a patch from PATCHES, but *do not* alter WORKING.\n\n";
247 out
<< " revert Remove LOCAL CHANGES. Note that this command is interactive,\n";
248 out
<< " so you can use it to revert only some of these changes.\n\n";
249 out
<< " unrevert Undo the last revert operation.\n\n";
250 // out << " unpull Delete a patch from PATCHES and unapply it from WORKING.\n";
251 // out << " Note that this command works for any patch, not just one that\n";
252 // out << " was previously \"pull\"ed. If there are no LOCAL CHANGES,\n";
253 // out << " this command is equivalent to \"vng unrecord; vng revert\"\n\n";
254 // out << " rollback Create the inverse of a particular patch and add it to PATCHES,\n";
255 // out << " but DO NOT apply it to WORKING. Note that this command is the\n";
256 // out << " only way to wind up with a patch in PATCHES which has not been\n";
257 // out << " applied to WORKING.\n\n";
262 int main(int argc
, char **argv
)
264 VngCommandLine
vng(argc
, argv
);