2 * This file is part of the vng project
3 * Copyright (C) 2008 Thomas Zander <tzander@trolltech.com>
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 #ifndef ABSTRACTCOMMAND_H
20 #define ABSTRACTCOMMAND_H
22 #include "Configuration.h"
27 #include <QTextStream>
30 * This baseclass can be used to inherit from in order to add new top-level commands to vng.
31 * Top level commands are things like 'whatsnew' and 'add'.
32 * @see CommandLineParser
34 class AbstractCommand
{
36 /// an enum of return codes to be used by start() and run() so all commands syncronize their codes.
38 // note that Unix requires 'Ok' to be zero.
53 * @param name the name this command has. Used (o.a.) to create a Configuration object.
55 AbstractCommand(const QString
&name
);
56 virtual ~AbstractCommand();
59 * Start the execution of the commmand.
60 * This will setup various items and read the default options after which it will call run().
61 * @return the exit code as used by the comamnd.
66 /// return the name of this command.
71 * return the short visual description of the arguments you can pass to this command.
72 * If the command takes arguments that are not options, you can make the help message print that
73 * by returning something in this method.
75 virtual QString
argumentDescription() const = 0;
78 * return long (multiline) Description of the command.
80 virtual QString
commandDescription() const = 0;
83 * Run the commmand from the repository root.
84 * @return the exit code as used by the comamnd.
87 virtual ReturnCodes
run() = 0;
89 /// returns the repository we are in.
90 QDir
repository() const;
91 /// returns if the command is a dry run which means that user interaction should take place, but no files changed.
94 /// The configuation object for this command.
95 Configuration m_config
;
98 * Changes the arguments passed like they are paths to compensate for the repodir.
99 * In vng all commands work on the whole repo, which is accomplished by changing the current
100 * directory to the repo root before run() is called.
101 * In case the user passed relative path arguments the change in current directory needs to be
102 * reflected in the paths.
103 * This method will take all the arguments and assume they are paths. For relative paths (not
104 * starting with slash or a drive name) the change in directory will be applied.
106 QStringList
rebasedArguments() const;
108 /// check if we are in a repository; return true if we are
109 bool checkInRepository() const;
111 bool shouldUsePager() const;
113 enum RebaseOptionFlag
{
114 NoOption
= 0, ///< No options
115 /// For each command line argument, do a stat to find if the original file or the rebased file is meant.
117 /// In case the rebased filename does not exist, print an error message saying so.
120 Q_DECLARE_FLAGS( RebaseOptions
, RebaseOptionFlag
)
122 /// make the current directory for vng the root of the repo. This will also populate the m_rebasedArguments list.
123 void moveToRoot(RebaseOptions options
= NoOption
);
129 QStringList m_rebasedArguments
;