OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 library command_lish; | 5 library command_lish; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'dart:io'; | 8 import 'dart:io'; |
9 import 'dart:json'; | 9 import 'dart:json'; |
10 import 'dart:uri'; | 10 import 'dart:uri'; |
11 | 11 |
12 import 'package:args/args.dart'; | 12 import 'package:args/args.dart'; |
13 import 'package:http/http.dart' as http; | 13 import 'package:http/http.dart' as http; |
14 import 'package:pathos/path.dart' as path; | 14 import 'package:pathos/path.dart' as path; |
15 | 15 |
16 import 'command.dart'; | 16 import 'command.dart'; |
17 import 'directory_tree.dart'; | 17 import 'directory_tree.dart'; |
18 import 'exit_codes.dart' as exit_codes; | 18 import 'exit_codes.dart' as exit_codes; |
19 import 'git.dart' as git; | 19 import 'git.dart' as git; |
| 20 import 'hosted_source.dart'; |
20 import 'http.dart'; | 21 import 'http.dart'; |
21 import 'io.dart'; | 22 import 'io.dart'; |
22 import 'log.dart' as log; | 23 import 'log.dart' as log; |
23 import 'oauth2.dart' as oauth2; | 24 import 'oauth2.dart' as oauth2; |
24 import 'utils.dart'; | 25 import 'utils.dart'; |
25 import 'validator.dart'; | 26 import 'validator.dart'; |
26 | 27 |
27 /// Handles the `lish` and `publish` pub commands. | 28 /// Handles the `lish` and `publish` pub commands. |
28 class LishCommand extends PubCommand { | 29 class LishCommand extends PubCommand { |
29 final description = "Publish the current package to pub.dartlang.org."; | 30 final description = "Publish the current package to pub.dartlang.org."; |
30 final usage = "pub publish [options]"; | 31 final usage = "pub publish [options]"; |
31 final aliases = const ["lish", "lush"]; | 32 final aliases = const ["lish", "lush"]; |
32 | 33 |
33 ArgParser get commandParser { | |
34 var parser = new ArgParser(); | |
35 // TODO(nweiz): Use HostedSource.defaultUrl as the default value once we use | |
36 // dart:io for HTTPS requests. | |
37 parser.addFlag('dry-run', abbr: 'n', negatable: false, | |
38 help: 'Validate but do not publish the package.'); | |
39 parser.addFlag('force', abbr: 'f', negatable: false, | |
40 help: 'Publish without confirmation if there are no errors.'); | |
41 parser.addOption('server', defaultsTo: 'https://pub.dartlang.org', | |
42 help: 'The package server to which to upload this package.'); | |
43 return parser; | |
44 } | |
45 | |
46 /// The URL of the server to which to upload the package. | 34 /// The URL of the server to which to upload the package. |
47 Uri get server => Uri.parse(commandOptions['server']); | 35 Uri get server => Uri.parse(commandOptions['server']); |
48 | 36 |
49 /// Whether the publish is just a preview. | 37 /// Whether the publish is just a preview. |
50 bool get dryRun => commandOptions['dry-run']; | 38 bool get dryRun => commandOptions['dry-run']; |
51 | 39 |
52 /// Whether the publish requires confirmation. | 40 /// Whether the publish requires confirmation. |
53 bool get force => commandOptions['force']; | 41 bool get force => commandOptions['force']; |
54 | 42 |
| 43 LishCommand() { |
| 44 commandParser.addFlag('dry-run', abbr: 'n', negatable: false, |
| 45 help: 'Validate but do not publish the package.'); |
| 46 commandParser.addFlag('force', abbr: 'f', negatable: false, |
| 47 help: 'Publish without confirmation if there are no errors.'); |
| 48 commandParser.addOption('server', defaultsTo: HostedSource.DEFAULT_URL, |
| 49 help: 'The package server to which to upload this package.'); |
| 50 } |
| 51 |
55 Future _publish(packageBytes) { | 52 Future _publish(packageBytes) { |
56 var cloudStorageUrl; | 53 var cloudStorageUrl; |
57 return oauth2.withClient(cache, (client) { | 54 return oauth2.withClient(cache, (client) { |
58 // TODO(nweiz): Cloud Storage can provide an XML-formatted error. We | 55 // TODO(nweiz): Cloud Storage can provide an XML-formatted error. We |
59 // should report that error and exit. | 56 // should report that error and exit. |
60 var newUri = server.resolve("/packages/versions/new.json"); | 57 var newUri = server.resolve("/packages/versions/new.json"); |
61 return client.get(newUri).then((response) { | 58 return client.get(newUri).then((response) { |
62 var parameters = parseJsonResponse(response); | 59 var parameters = parseJsonResponse(response); |
63 | 60 |
64 var url = _expectField(parameters, 'url', response); | 61 var url = _expectField(parameters, 'url', response); |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 return confirm(message).then((confirmed) { | 162 return confirm(message).then((confirmed) { |
166 if (!confirmed) { | 163 if (!confirmed) { |
167 log.error("Package upload canceled."); | 164 log.error("Package upload canceled."); |
168 return false; | 165 return false; |
169 } | 166 } |
170 return true; | 167 return true; |
171 }); | 168 }); |
172 }); | 169 }); |
173 } | 170 } |
174 } | 171 } |
OLD | NEW |