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"
25 #include "Initialize.h"
33 #include <QTextStream>
35 #define VERSION "vng version 0.22 (>2008-03-28)"
37 VngCommandLine::VngCommandLine(int argc
, char **argv
)
38 : QCoreApplication(argc
, argv
)
40 CommandLineParser::init(argc
, argv
);
42 m_command
= QString(argv
[1]);
45 VngCommandLine::~VngCommandLine()
47 delete CommandLineParser::instance();
50 int VngCommandLine::run()
52 if (m_command
== "--extended-help") {
56 if (m_command
== "--version" || m_command
== "-v"
61 QTextStream
out(stdout
);
62 out
<< VERSION
<< endl
;
65 if (m_command
.isEmpty()) {
70 // autoComplete command
72 // keep this list sorted in the sourcecode. In vim just select the lines and do a :'<,'>!sort
75 commands
<< "initialize";
79 commands
<< "unrecord";
80 commands
<< "unrevert";
81 commands
<< "whatsnew";
83 if (m_command
== "--commands") { // for commandline completion.
84 Configuration
config("");
85 QTextStream
out(stdout
);
86 out
<< "help" << endl
;
87 out
<< "--help" << endl
;
88 out
<< "--version" << endl
;
89 out
<< "--extended--help" << endl
;
90 if (QDir(config
.repository().absolutePath() + "/.git").exists()) {
92 out
<< "push" << endl
;
93 out
<< "record" << endl
;
94 out
<< "revert" << endl
;
95 out
<< "unrecord" << endl
;
96 out
<< "unrevert" << endl
;
97 out
<< "whatsnew" << endl
;
104 foreach(QString s
, commands
) {
105 if (m_command
== s
) { // perfect match
109 if (! command
.isEmpty()) {
110 if (s
.startsWith(m_command
)) {
111 QTextStream
out(stdout
);
112 out
<< "vng failed: " << "Ambiguous command..." << endl
;
116 break; // found best match.
118 if (s
.startsWith(m_command
)) {
123 if (command
.isEmpty()) {
124 if (! m_command
.isEmpty()) {
125 QTextStream
out(stdout
);
126 out
<< "vng failed: " << "Invalid command `" << m_command
<< "'\n\n";
133 AbstractCommand
*ac
= 0;
134 if (m_command
== "whatsnew")
136 else if (m_command
== "add")
138 else if (m_command
== "initialize")
139 ac
= new Initialize();
140 else if (m_command
== "push")
142 else if (m_command
== "revert")
144 else if (m_command
== "unrecord")
146 else if (m_command
== "unrevert")
148 else if (command
== "help") {
152 else if (m_command
== "record")
159 void VngCommandLine::printHelp()
161 QTextStream
out(stdout
);
162 out
<< "Usage: vng COMMAND ...\n\n" << VERSION
<< endl
;
163 out
<< "Commands:" << endl
;
164 out
<< " help Display help for vng or a single commands." << endl
;
165 out
<< "Changing and querying the working copy:" << endl
;
166 out
<< " add Add one or more new files or directories." << endl
;
167 out
<< " revert Revert to the recorded version (safe the first time only)." << endl
;
168 out
<< " unrevert Undo the last revert (may fail if changes after the revert)." << endl
;
169 out
<< " whatsnew Display unrecorded changes in the working copy." << endl
;
170 out
<< "Copying changes between the working copy and the repository:" << endl
;
171 out
<< " record Save changes in the working copy to the repository as a patch." << endl
;
172 out
<< " unrecord Remove recorded patches without changing the working copy." << endl
;
173 out
<< "Copying patches between repositories with working copy update:" << endl
;
174 out
<< " push Copy and apply patches from this repository to another one." << endl
;
175 out
<< "Administrating repositories:" << endl
;
176 out
<< " initialize Initialize a new source tree as a vng repository." << endl
;
178 out
<< "Use 'vng --extended-help' for more detailed help." << endl
;
179 out
<< "Use 'vng COMMAND --help' for help on a single command." << endl
;
180 out
<< "Use 'vng --version' to see the vng version number." << endl
;
183 void VngCommandLine::printExtendedHelp()
185 QTextStream
out(stdout
);
186 out
<< VERSION
<< endl
;
187 out
<< "Usage: vng COMMAND ...\n\n";
188 out
<< "Extended Help:\n\n";
189 out
<< "A vng repository consists of:\n\n";
190 out
<< " - a set of PATCHES\n";
191 out
<< " - a WORKING directory\n\n";
192 out
<< "Here is a description of which of these components is altered by each\n";
193 out
<< "command, and how it is used or altered:\n\n";
194 out
<< " whatsnew Show the differences between WORKING and the \"recorded\"\n";
195 out
<< " version, that is, the result of applying all PATCHES in the\n";
196 out
<< " repository. This difference, we will call LOCAL CHANGES.\n\n";
197 out
<< " record Add a patch to PATCHES representing the LOCAL CHANGES.\n\n";
198 out
<< " unrecord Delete a patch from PATCHES, but *do not* alter WORKING.\n\n";
199 out
<< " revert Remove LOCAL CHANGES. Note that this command is interactive,\n";
200 out
<< " so you can use it to revert only some of these changes.\n\n";
201 out
<< " unrevert Undo the last revert operation.\n\n";
202 // out << " unpull Delete a patch from PATCHES and unapply it from WORKING.\n";
203 // out << " Note that this command works for any patch, not just one that\n";
204 // out << " was previously \"pull\"ed. If there are no LOCAL CHANGES,\n";
205 // out << " this command is equivalent to \"vng unrecord; vng revert\"\n\n";
206 // out << " rollback Create the inverse of a particular patch and add it to PATCHES,\n";
207 // out << " but DO NOT apply it to WORKING. Note that this command is the\n";
208 // out << " only way to wind up with a patch in PATCHES which has not been\n";
209 // out << " applied to WORKING.\n\n";
214 int main(int argc
, char **argv
)
216 VngCommandLine
vng(argc
, argv
);