-
Notifications
You must be signed in to change notification settings - Fork 1
/
cli.dart
250 lines (234 loc) · 8.05 KB
/
cli.dart
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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
library bwu_dart_archive_downloader.src.cli;
import 'dart:io' as io;
import 'package:bwu_dart_archive_downloader/bwu_dart_archive_downloader.dart';
import 'package:unscripted/unscripted.dart';
import 'package:pub_semver/pub_semver.dart';
import 'package:bwu_dart_archive_downloader/dart_update.dart';
import 'package:logging/logging.dart' show Logger, Level;
import 'package:quiver_log/log.dart' show BASIC_LOG_FORMATTER, PrintAppender;
import 'package:stack_trace/stack_trace.dart' show Chain;
final _log = new Logger('bwu_dart_archive_downloader.src.cli');
void main(List<String> args) {
Logger.root.level = Level.INFO;
var appender = new PrintAppender(BASIC_LOG_FORMATTER);
appender.attachLogger(Logger.root);
Chain.capture(() => _main(args), onError: (error, stack) {
_log.shout(error);
_log.shout(stack.terse);
});
}
_main([List<String> arguments]) =>
new Script(DownloadCommandModel).execute(arguments);
class DDownScriptModel extends Object with DownloadCommandModel {
@Command(
allowTrailingOptions: false,
help: 'Download a file from the Dart archive.',
plugins: const [const Completion()])
DDownScriptModel();
}
class DownloadCommandModel {
@SubCommand(help: '''
Download a file from the Dart archive (http://gsdview.appspot.com/dart-archive/channels/).
Version and download channel can be selected.''')
down({@Option(help: '''
The base name of the file to download excluding extensions like "-ia32", ".md5sum", ... .''',
abbr: 'f') //
// defaultsTo: defaultStaticFilesSourceDirectory) //
String filename, //
@Option(help: '''
The absolute or relative path where the directory should be created.''',
abbr: 'o',
defaultsTo: '.') //
String outputDirectory,
//
@Option(help: '''
The version to download.''', abbr: 'v', defaultsTo: 'latest') //
String version,
//
@Option(help: '''
The channel to download from.
Possible values:
- stable/raw
- stable/release
- stable/signed
- dev/raw
- dev/raw
- dev/signed
- be/raw
''', //
abbr: 'c', defaultsTo: 'stable/release') //
String channel,
//
@Option(help: '''
Choose a folder in the archive:
Possible values:
- api-docs
- dartium
- dartium_android
- (editor-eclipse-update - not implemented)
- (editor - not implemented)
- sdk
- VERSION
''', abbr: 'a', defaultsTo: 'sdk') //
String artifact,
//
@Option(help: '''
The target operating system and architecture. If omitted it will be derived
from the system.
Possible values:
- android-arm
- linux-ia32
- linux-x64
- macos-ia32
- windows-ia32
''', abbr: 'p') //
// defaultsTo: 'current system') //
String platform, @Option(help: '''
Choose an addon-file instead of the main file.
Possible values:
- md5sum
- sha256sum
''', abbr: 's', defaultsTo: '') //
String fileAddition,
//
@Flag(help: '''
If "platform" is omitted and derived from the system, should it download the
64 bit version if available?.''',
abbr: 'b',
defaultsTo: true,
negatable: true) //
bool prefer64bit, //
@Flag(help: '''
Get the debug build of the file.''',
// abbr: 'd',
defaultsTo: false, negatable: true) //
bool debugBuild, //
@Flag(help: '''
Extract the downloaded ZIP archive file.''',
abbr: 'e',
defaultsTo: false,
negatable: true) //
bool extract, //
@Option(help: '''
Extracts the ZIP archive top-level directory into the the "extractAs" directory.''',
abbr: 'd') //
// defaultsTo: '.') //
String extractAs, //
@Option(help: '''
Extracts the ZIP archive top-level directory into the the "extractAs" directory.''',
abbr: 't',
defaultsTo: '.') //
String extractTo, //
@Flag(help: '''
Verbose logging output.''', defaultsTo: false, negatable: true) //
bool verbose}) async {
if (verbose) {
Logger.root.level = Level.FINEST;
}
final downloader = new DartArchiveDownloader(outputDirectory == '.'
? io.Directory.current
: new io.Directory(outputDirectory));
final Iterable<DownloadChannel> channels =
DownloadChannel.values.where((v) => v.value.startsWith(channel));
if (channels.isEmpty) {
throw 'Channel "${channel}" isn\'t supported or recognized.';
} else {
_log.fine('Using channel "${channels.first.value}".');
}
String versionDirectory;
if (version == 'latest') {
versionDirectory = version;
} else {
Version parsedVersion;
try {
parsedVersion = new Version.parse(version);
} catch (e) {
throw 'Version "${version}" can\'t be parsed.';
}
versionDirectory =
await downloader.findVersion(channels.first, parsedVersion);
}
final Iterable<DownloadArtifact> artifacts =
DownloadArtifact.values.where((v) => v.value.startsWith(artifact));
if (artifacts.isEmpty) {
throw 'Artifact "${artifact}" isn\'t supported or recognized.';
} else {
_log.fine('Using artifact "${artifacts.first.value}".');
}
final Iterable<FileAddition> fileAdditions =
FileAddition.values.where((v) => v.value.startsWith(fileAddition));
if (fileAdditions.isEmpty) {
throw 'FileAddition "${fileAddition}" isn\'t supported or recognized.';
} else {
_log.fine('Using file addition "${fileAdditions.first.value}".');
}
Iterable<Platform> platforms;
if (platform == null || platform.isEmpty) {
platforms = [Platform.getFromSystemPlatform(prefer64bit: prefer64bit)];
} else {
platforms = Platform.values.where((v) => v.value.startsWith(platform));
if (platforms.isEmpty) {
throw 'Platform "${platform}" isn\'t supported or recognized.';
} else {
_log.fine('Using platform "${platforms.first.value}".');
}
}
DownloadFile downloadFile;
switch (artifacts.first) {
case DownloadArtifact.apiDocs:
downloadFile = ApiDocsFile.dartApiDocsZip;
if (filename != null) {
_log.fine('Ignoring parameter filename ("${filename}").');
}
break;
case DownloadArtifact.dartium:
final fileConstructors =
DartiumFile.values.keys.where((v) => v.startsWith(filename));
if (fileConstructors.isEmpty) {
throw 'File "${filename}" isn\'t supported or recognized.';
} else {
_log.fine('Using download file "${fileConstructors.first}".');
}
downloadFile = DartiumFile.values[fileConstructors.first](
platforms.first,
debug: debugBuild, fileAddition: fileAdditions.first);
break;
case DownloadArtifact.dartiumAndroid:
downloadFile = DartiumAndroidFile.contentShell;
if (filename != null) {
_log.fine('Ignoring parameter filename ("${filename}").');
}
break;
case DownloadArtifact.eclipseUpdate:
throw 'Download Eclipse updates isn\'t yet implemented.';
break;
case DownloadArtifact.editor:
throw 'Download DartEditor isn\'t yet implemented.';
break;
case DownloadArtifact.sdk:
downloadFile = new SdkFile.dartSdk(platforms.first,
debug: debugBuild, fileAddition: fileAdditions.first);
if (filename != null) {
_log.fine('Ignoring parameter filename ("${filename}").');
}
break;
case DownloadArtifact.version:
downloadFile = VersionFile.version;
if (filename != null) {
_log.fine('Ignoring parameter filename ("${filename}").');
}
break;
default:
// Unsupported artifacts are handled above.
break;
}
final uri = channels.first.getUri(downloadFile, version: versionDirectory);
io.File archiveFile = await downloader.downloadFile(uri);
if (extract) {
installArchive(archiveFile, new io.Directory(extractTo),
replaceRootDirectoryName: extractAs != null && extractAs.isNotEmpty
? extractAs
: null);
}
}
}