/
TerminalOptionsBuilder.java
225 lines (217 loc) · 9.45 KB
/
TerminalOptionsBuilder.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
package ch.cyberduck.cli;
/*
* Copyright (c) 2002-2014 David Kocher. All rights reserved.
* http://cyberduck.io/
*
* 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 2 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.
*
* Bug fixes, suggestions and comments should be sent to:
* feedback@cyberduck.io
*/
import ch.cyberduck.core.transfer.Transfer;
import ch.cyberduck.core.transfer.TransferAction;
import org.apache.commons.cli.OptionBuilder;
import org.apache.commons.cli.Options;
import org.apache.commons.lang3.StringUtils;
import java.util.Collections;
/**
* @version $Id$
*/
public final class TerminalOptionsBuilder {
private TerminalOptionsBuilder() {
//
}
public static Options options() {
final Options options = new Options();
options.addOption(OptionBuilder
.withDescription("Username")
.withLongOpt(Params.username.name())
.hasArg(true).withArgName("username or access key")
.isRequired(false)
.create('u'));
options.addOption(OptionBuilder
.withDescription("Password")
.withLongOpt(Params.password.name())
.hasArg(true).withArgName("password or secret key")
.isRequired(false)
.create('p'));
options.addOption(OptionBuilder
.withDescription("Selects a file from which the identity (private key) for public key authentication is read")
.withLongOpt(Params.identity.name())
.hasArg(true).withArgName("private key file")
.isRequired(false)
.create('i'));
options.addOption(OptionBuilder
.withDescription("Download file or folder. Denote a folder with a trailing '/'")
.withLongOpt(TerminalAction.download.name())
.hasArgs(2).withArgName("url> <[file]").withValueSeparator(' ')
.isRequired(false)
.create('d'));
options.addOption(OptionBuilder
.withDescription("Upload file or folder recursively")
.withLongOpt(TerminalAction.upload.name())
.hasArgs(2).withArgName("url> <file").withValueSeparator(' ')
.isRequired(false)
.create());
options.addOption(OptionBuilder
.withDescription("Copy between servers")
.withLongOpt(TerminalAction.copy.name())
.hasArgs(2).withArgName("url> <url").withValueSeparator(' ')
.isRequired(false)
.create());
options.addOption(OptionBuilder
.withDescription("Synchronize folders")
.withLongOpt(TerminalAction.synchronize.name())
.hasArgs(2).withArgName("url> <directory").withValueSeparator(' ')
.isRequired(false)
.create());
options.addOption(OptionBuilder
.withDescription("Edit file in external editor")
.withLongOpt(TerminalAction.edit.name())
.hasArgs(1).withArgName("url")
.isRequired(false)
.create());
options.addOption(OptionBuilder
.withDescription("External editor application")
.withLongOpt(Params.application.name())
.hasArgs(1).withArgName("path")
.isRequired(false)
.create());
options.addOption(OptionBuilder
.withDescription("List files in remote folder")
.withLongOpt(TerminalAction.list.name())
.hasArg(true).withArgName("url")
.isRequired(false)
.create("l"));
options.addOption(OptionBuilder
.withDescription("Delete")
.withLongOpt(TerminalAction.delete.name())
.hasArg(true).withArgName("url")
.isRequired(false)
.create("D"));
options.addOption(OptionBuilder
.withDescription("Long list format with modification date and permission mask")
.withLongOpt(Params.longlist.name())
.hasArg(false)
.isRequired(false)
.create('L'));
options.addOption(OptionBuilder
.withDescription("Location of bucket or container")
.withLongOpt(Params.region.name())
.hasArg(true).withArgName("location")
.isRequired(false)
.create());
options.addOption(OptionBuilder
.withDescription("Preserve permissions and modification date for transferred files")
.withLongOpt(Params.preserve.name())
.hasArg(false)
.isRequired(false)
.create('P'));
options.addOption(OptionBuilder
.withDescription("Retry failed connection attempts")
.withLongOpt(Params.retry.name())
.hasOptionalArg().withArgName("count")
.isRequired(false)
.create('r'));
options.addOption(OptionBuilder
.withDescription("Use UDT protocol if applicable")
.withLongOpt(Params.udt.name())
.isRequired(false)
.create());
options.addOption(OptionBuilder
.withDescription("Number of concurrent connections to use for transfers")
.withLongOpt(Params.parallel.name())
.hasOptionalArg().withArgName("connections")
.isRequired(false)
.create());
options.addOption(OptionBuilder
.withDescription("Throttle bandwidth")
.withLongOpt(Params.throttle.name())
.hasArg(true).withArgName("bytes per second")
.isRequired(false)
.create());
options.addOption(OptionBuilder
.withDescription("Do not save passwords in keychain")
.withLongOpt(Params.nokeychain.name())
.isRequired(false)
.create());
final StringBuilder b = new StringBuilder().append(StringUtils.LF);
b.append("Options for downloads and uploads:").append(StringUtils.LF);
for(TransferAction a : TransferAction.forTransfer(Transfer.Type.download)) {
b.append("\t").append(a.getTitle()).append("\t").append(a.getDescription()).append(String.format(" (%s)", a.name())).append(StringUtils.LF);
}
for(TransferAction a : Collections.singletonList(TransferAction.cancel)) {
b.append("\t").append(a.getTitle()).append("\t").append(a.getDescription()).append(String.format(" (%s)", a.name())).append(StringUtils.LF);
}
b.append("Options for synchronize:").append(StringUtils.LF);
for(TransferAction a : TransferAction.forTransfer(Transfer.Type.sync)) {
b.append("\t").append(a.getTitle()).append("\t").append(a.getDescription()).append(String.format(" (%s)", a.name())).append(StringUtils.LF);
}
for(TransferAction a : Collections.singletonList(TransferAction.cancel)) {
b.append("\t").append(a.getTitle()).append("\t").append(a.getDescription()).append(String.format(" (%s)", a.name())).append(StringUtils.LF);
}
options.addOption(OptionBuilder
.withDescription(String.format("Transfer action for existing files%s", b.toString()))
.withLongOpt(Params.existing.name())
.hasArg(true).withArgName("action")
.isRequired(false)
.create('e'));
options.addOption(OptionBuilder
.withDescription("Print transcript")
.withLongOpt(Params.verbose.name())
.hasArg(false)
.isRequired(false)
.create('v'));
options.addOption(OptionBuilder
.withDescription("Suppress progress messages")
.withLongOpt(Params.quiet.name())
.hasArg(false)
.isRequired(false)
.create('q'));
options.addOption(OptionBuilder
.withDescription("Assume yes for all prompts")
.withLongOpt(Params.assumeyes.name())
.hasArg(false)
.isRequired(false)
.create('y'));
options.addOption(OptionBuilder
.withDescription("Show version number and quit")
.withLongOpt(TerminalAction.version.name())
.hasArg(false)
.isRequired(false)
.create('V'));
options.addOption(OptionBuilder
.withDescription("Print this help")
.withLongOpt(TerminalAction.help.name())
.hasArg(false)
.isRequired(false)
.create("h"));
return options;
}
public enum Params {
region,
longlist,
preserve,
retry,
udt,
parallel,
throttle,
nokeychain,
existing,
verbose,
quiet,
assumeyes,
username,
password,
identity,
application
}
}