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 pub.command.lish; | 5 library pub.command.lish; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 | 8 |
9 import 'package:http/http.dart' as http; | 9 import 'package:http/http.dart' as http; |
10 | 10 |
11 import '../command.dart'; | 11 import '../command.dart'; |
12 import '../ascii_tree.dart' as tree; | 12 import '../ascii_tree.dart' as tree; |
13 import '../http.dart'; | 13 import '../http.dart'; |
14 import '../io.dart'; | 14 import '../io.dart'; |
15 import '../log.dart' as log; | 15 import '../log.dart' as log; |
16 import '../oauth2.dart' as oauth2; | 16 import '../oauth2.dart' as oauth2; |
17 import '../source/hosted.dart'; | 17 import '../source/hosted.dart'; |
18 import '../utils.dart'; | 18 import '../utils.dart'; |
19 import '../validator.dart'; | 19 import '../validator.dart'; |
20 | 20 |
21 /// Handles the `lish` and `publish` pub commands. | 21 /// Handles the `lish` and `publish` pub commands. |
22 class LishCommand extends PubCommand { | 22 class LishCommand extends PubCommand { |
23 String get description => "Publish the current package to pub.dartlang.org."; | 23 String get description => "Publish the current package to pub.dartlang.org."; |
24 String get usage => "pub publish [options]"; | 24 String get usage => "pub publish [options]"; |
25 String get docUrl => "http://dartlang.org/tools/pub/cmd/pub-lish.html"; | 25 String get docUrl => "http://dartlang.org/tools/pub/cmd/pub-lish.html"; |
26 List<String> get aliases => const ["lish", "lush"]; | 26 List<String> get aliases => const ["lish", "lush"]; |
27 | 27 |
28 /// The URL of the server to which to upload the package. | 28 /// The URL of the server to which to upload the package. |
29 Uri get server => Uri.parse(commandOptions['server']); | 29 Uri get server { |
30 // An explicit argument takes precedence. | |
31 if (commandOptions.wasParsed('server')) { | |
32 return Uri.parse(commandOptions['server']); | |
33 } | |
34 | |
35 // Otherwise, use the one specified in the pubspec. | |
36 if (entrypoint.root.pubspec.publishTo != null) { | |
37 return Uri.parse(entrypoint.root.pubspec.publishTo); | |
38 } | |
39 | |
40 // Otherwise, use the default. | |
41 return Uri.parse(HostedSource.defaultUrl); | |
42 } | |
30 | 43 |
31 /// Whether the publish is just a preview. | 44 /// Whether the publish is just a preview. |
32 bool get dryRun => commandOptions['dry-run']; | 45 bool get dryRun => commandOptions['dry-run']; |
33 | 46 |
34 /// Whether the publish requires confirmation. | 47 /// Whether the publish requires confirmation. |
35 bool get force => commandOptions['force']; | 48 bool get force => commandOptions['force']; |
36 | 49 |
37 LishCommand() { | 50 LishCommand() { |
38 commandParser.addFlag('dry-run', abbr: 'n', negatable: false, | 51 commandParser.addFlag('dry-run', abbr: 'n', negatable: false, |
39 help: 'Validate but do not publish the package.'); | 52 help: 'Validate but do not publish the package.'); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
91 throw error; | 104 throw error; |
92 } | 105 } |
93 }); | 106 }); |
94 } | 107 } |
95 | 108 |
96 Future onRun() { | 109 Future onRun() { |
97 if (force && dryRun) { | 110 if (force && dryRun) { |
98 usageError('Cannot use both --force and --dry-run.'); | 111 usageError('Cannot use both --force and --dry-run.'); |
99 } | 112 } |
100 | 113 |
114 if (entrypoint.root.pubspec.isPrivate) { | |
115 dataError("A private package cannot be published."); | |
nweiz
2014/08/01 01:12:13
Consider associating this with the "publishTo" spa
Bob Nystrom
2014/08/04 21:16:43
Didn't add the span, but did mention "publishTo" i
| |
116 } | |
117 | |
101 var files = entrypoint.root.listFiles(); | 118 var files = entrypoint.root.listFiles(); |
102 log.fine('Archiving and publishing ${entrypoint.root}.'); | 119 log.fine('Archiving and publishing ${entrypoint.root}.'); |
103 | 120 |
104 // Show the package contents so the user can verify they look OK. | 121 // Show the package contents so the user can verify they look OK. |
105 var package = entrypoint.root; | 122 var package = entrypoint.root; |
106 log.message( | 123 log.message( |
107 'Publishing ${package.name} ${package.version} to $server:\n' | 124 'Publishing ${package.name} ${package.version} to $server:\n' |
108 '${tree.fromFiles(files, baseDir: entrypoint.root.dir)}'); | 125 '${tree.fromFiles(files, baseDir: entrypoint.root.dir)}'); |
109 | 126 |
110 var packageBytesFuture = createTarGz(files, baseDir: entrypoint.root.dir) | 127 var packageBytesFuture = createTarGz(files, baseDir: entrypoint.root.dir) |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
157 return confirm(message).then((confirmed) { | 174 return confirm(message).then((confirmed) { |
158 if (!confirmed) { | 175 if (!confirmed) { |
159 log.error("Package upload canceled."); | 176 log.error("Package upload canceled."); |
160 return false; | 177 return false; |
161 } | 178 } |
162 return true; | 179 return true; |
163 }); | 180 }); |
164 }); | 181 }); |
165 } | 182 } |
166 } | 183 } |
OLD | NEW |