Don't allow to unrecord past the branch point
[vng.git] / AbstractCommand.h
blob0cfa9235e67c987dba72ee133f0ed394f635a0dc
1 /*
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"
24 #include <QString>
25 #include <QProcess>
26 #include <QDir>
27 #include <QTextStream>
29 /**
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 {
35 public:
36 /// an enum of return codes to be used by start() and run() so all commands syncronize their codes.
37 enum ReturnCodes {
38 // note that Unix requires 'Ok' to be zero.
39 Ok = 0,
40 InvalidOptions = 1,
41 Disabled,
42 NotInRepo,
43 WriteError,
44 GitCrashed = 10,
45 GitFailed,
46 GitTimedOut,
47 GnuDiffFailed
50 /**
51 * Constructor.
52 * @param name the name this command has. Used (o.a.) to create a Configuration object.
54 AbstractCommand(const QString &name);
55 virtual ~AbstractCommand();
57 /**
58 * Start the execution of the commmand.
59 * This will setup various items and read the default options after which it will call run().
60 * @return the exit code as used by the comamnd.
61 * @see ReturnCodes
63 ReturnCodes start();
65 /// return the name of this command.
66 QString name() const;
68 protected:
69 /**
70 * return the short visual description of the arguments you can pass to this command.
71 * If the command takes arguments that are not options, you can make the help message print that
72 * by returning something in this method.
74 virtual QString argumentDescription() const = 0;
76 /**
77 * return long (multiline) Description of the command.
79 virtual QString commandDescription() const = 0;
81 /**
82 * Run the commmand from the repository root.
83 * @return the exit code as used by the comamnd.
84 * @see ReturnCodes
86 virtual ReturnCodes run() = 0;
88 /// returns the repository we are in.
89 QDir repository() const;
90 /// returns if the command is a dry run which means that user interaction should take place, but no files changed.
91 bool dryRun() const;
93 /// The configuation object for this command.
94 Configuration m_config;
96 /**
97 * Changes the arguments passed like they are paths to compensate for the repodir.
98 * In vng all commands work on the whole repo, which is accomplished by changing the current
99 * directory to the repo root before run() is called.
100 * In case the user passed relative path arguments the change in current directory needs to be
101 * reflected in the paths.
102 * This method will take all the arguments and assume they are paths. For relative paths (not
103 * starting with slash or a drive name) the change in directory will be applied.
105 QStringList rebasedArguments() const;
107 /// check if we are in a repository; return true if we are
108 bool checkInRepository() const;
110 bool shouldUsePager() const;
112 private:
113 QDir m_repository;
114 bool m_dryRun;
115 QString m_name;
116 QStringList m_rebasedArguments;
119 #endif