This repository has been archived by the owner on Jul 26, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 217
/
Command.java
86 lines (78 loc) · 3.39 KB
/
Command.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/*
* Syncany, www.syncany.org
* Copyright (C) 2011-2013 Philipp C. Heckel <philipp.heckel@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.syncany.cli;
import java.io.File;
import java.io.PrintStream;
import org.syncany.Client;
/**
* Commands are the central part of Syncany's command line client. Each implementation
* of this abstract class represents a command that a user can run on the command line.
*
* <p>The purpose of a command is to read required and optional arguments from the command
* line, run the corresponding operation, and display the results on the console.
* Implementations are not supposed to actually run any detailed logic, but are merely
* the user interface to collection options and print operation output.
*
* <p>Implementations must implement the {@link #execute(String[]) execute()} method and
* the {@link #initializedLocalDirRequired()} method. While the former actually implements
* the logic, the latter specifies whether a command must be called inside (or outside) a
* local Syncany directory.
*
* <p>Commands are automatically mapped from their camel case name on the command line
* to a class name using the {@link CommandFactory}. The command 'ls-remote', for instance,
* is mapped to the <tt>LsRemoteCommand</tt>.
*
* @author Philipp C. Heckel <philipp.heckel@gmail.com>
*/
public abstract class Command {
protected File localDir;
protected Client client;
protected PrintStream out;
/**
* This method implements the command-specific option-parsing, operation calling
* and output printing. To do so, the method must read and evaluate the given
* arguments, prepare a corresponding operation, call it and display the results
* according to a well-defined format.
*
* <p>Implementations should not move any business logic in the execute method
* (or any other parts of the command).
*
* @param operationArgs Command-specific arguments (might also contain global options)
* @return Returns a return code
* @throws Exception If the command or the corresponding operation fails
*/
// TODO [low] Return code of commands not used right now
public abstract int execute(String[] operationArgs) throws Exception;
/**
* A command can either be executed within an initialized local directory or
* in a regular (non-Syncany) directory. This method must return <tt>true</tt>,
* if the command implementation requires an initialized Syncany directory.
*
* @return Returns <tt>true</tt> if an initialized local directory is required, <tt>false</tt> otherwise.
*/
public abstract boolean initializedLocalDirRequired();
public void setLocalDir(File localDir) {
this.localDir = localDir;
}
public void setClient(Client client) {
this.client = client;
}
public void setOut(PrintStream out) {
this.out = out;
}
}