Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(308)

Side by Side Diff: utils/pub/command_lish.dart

Issue 12226077: add --preview flag to publish command (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | utils/tests/pub/pub_lish_test.dart » ('j') | utils/tests/pub/pub_lish_test.dart » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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';
(...skipping 14 matching lines...) Expand all
25 /// Handles the `lish` and `publish` pub commands. 25 /// Handles the `lish` and `publish` pub commands.
26 class LishCommand extends PubCommand { 26 class LishCommand extends PubCommand {
27 final description = "Publish the current package to pub.dartlang.org."; 27 final description = "Publish the current package to pub.dartlang.org.";
28 final usage = "pub publish [options]"; 28 final usage = "pub publish [options]";
29 final aliases = const ["lish", "lush"]; 29 final aliases = const ["lish", "lush"];
30 30
31 ArgParser get commandParser { 31 ArgParser get commandParser {
32 var parser = new ArgParser(); 32 var parser = new ArgParser();
33 // TODO(nweiz): Use HostedSource.defaultUrl as the default value once we use 33 // TODO(nweiz): Use HostedSource.defaultUrl as the default value once we use
34 // dart:io for HTTPS requests. 34 // dart:io for HTTPS requests.
35 parser.addFlag('dry-run', abbr: 'n', negatable: false,
36 help: "Preview publishing the package\n"
37 "Validate but do not publish the package");
Bob Nystrom 2013/02/12 01:00:41 You can remove the "Preview..." line.
keertip 2013/02/12 05:20:20 Done.
35 parser.addOption('server', defaultsTo: 'https://pub.dartlang.org', 38 parser.addOption('server', defaultsTo: 'https://pub.dartlang.org',
36 help: 'The package server to which to upload this package'); 39 help: 'The package server to which to upload this package');
37 return parser; 40 return parser;
38 } 41 }
39 42
40 /// The URL of the server to which to upload the package. 43 /// The URL of the server to which to upload the package.
41 Uri get server => Uri.parse(commandOptions['server']); 44 Uri get server => Uri.parse(commandOptions['server']);
42 45
43 Future _publish(packageBytes) { 46 Future _publish(packageBytes) {
44 var cloudStorageUrl; 47 var cloudStorageUrl;
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 var package = entrypoint.root; 96 var package = entrypoint.root;
94 log.message( 97 log.message(
95 'Publishing "${package.name}" ${package.version}:\n' 98 'Publishing "${package.name}" ${package.version}:\n'
96 '${generateTree(files)}'); 99 '${generateTree(files)}');
97 100
98 return createTarGz(files, baseDir: entrypoint.root.dir); 101 return createTarGz(files, baseDir: entrypoint.root.dir);
99 }).then((stream) => stream.toBytes()); 102 }).then((stream) => stream.toBytes());
100 103
101 // Validate the package. 104 // Validate the package.
102 return _validate(packageBytesFuture.then((bytes) => bytes.length)) 105 return _validate(packageBytesFuture.then((bytes) => bytes.length))
103 .then((_) => packageBytesFuture).then(_publish); 106 .then((validate) {
Bob Nystrom 2013/02/12 01:00:41 "validate" -> "isValid"
keertip 2013/02/12 05:20:20 Done.
107 if (validate) return packageBytesFuture.then(_publish);
108 });
Bob Nystrom 2013/02/12 01:00:41 The styling of this is a bit strange. How about:
keertip 2013/02/12 05:20:20 Done.
104 } 109 }
105 110
106 /// The basenames of files that are automatically excluded from archives. 111 /// The basenames of files that are automatically excluded from archives.
107 final _BLACKLISTED_FILES = const ['pubspec.lock']; 112 final _BLACKLISTED_FILES = const ['pubspec.lock'];
108 113
109 /// The basenames of directories that are automatically excluded from 114 /// The basenames of directories that are automatically excluded from
110 /// archives. 115 /// archives.
111 final _BLACKLISTED_DIRS = const ['packages']; 116 final _BLACKLISTED_DIRS = const ['packages'];
112 117
113 /// Returns a list of files that should be included in the published package. 118 /// Returns a list of files that should be included in the published package.
114 /// If this is a Git repository, this will respect .gitignore; otherwise, it 119 /// If this is a Git repository, this will respect .gitignore; otherwise, it
115 /// will return all non-hidden files. 120 /// will return all non-hidden files.
(...skipping 23 matching lines...) Expand all
139 } 144 }
140 145
141 /// Returns the value associated with [key] in [map]. Throws a user-friendly 146 /// Returns the value associated with [key] in [map]. Throws a user-friendly
142 /// error if [map] doens't contain [key]. 147 /// error if [map] doens't contain [key].
143 _expectField(Map map, String key, http.Response response) { 148 _expectField(Map map, String key, http.Response response) {
144 if (map.containsKey(key)) return map[key]; 149 if (map.containsKey(key)) return map[key];
145 invalidServerResponse(response); 150 invalidServerResponse(response);
146 } 151 }
147 152
148 /// Validates the package. Throws an exception if it's invalid. 153 /// Validates the package. Throws an exception if it's invalid.
149 Future _validate(Future<int> packageSize) { 154 Future<bool> _validate(Future<int> packageSize) {
150 return Validator.runAll(entrypoint, packageSize).then((pair) { 155 return Validator.runAll(entrypoint, packageSize).then((pair) {
151 var errors = pair.first; 156 var errors = pair.first;
152 var warnings = pair.last; 157 var warnings = pair.last;
153 158
154 if (!errors.isEmpty) { 159 if (!errors.isEmpty) {
155 throw "Sorry, your package is missing " 160 throw "Sorry, your package is missing "
156 "${(errors.length > 1) ? 'some requirements' : 'a requirement'} " 161 "${(errors.length > 1) ? 'some requirements' : 'a requirement'} "
157 "and can't be published yet.\nFor more information, see: " 162 "and can't be published yet.\nFor more information, see: "
158 "http://pub.dartlang.org/doc/pub-lish.html.\n"; 163 "http://pub.dartlang.org/doc/pub-lish.html.\n";
Bob Nystrom 2013/02/12 01:00:41 Instead of throwing, just use log.error() to print
keertip 2013/02/12 05:20:20 With this change, publish will return with exitcod
Bob Nystrom 2013/02/12 19:00:57 Hmm. Good point. I think I'm OK with that for now
159 } 164 }
160 165
166 if (commandOptions['dry-run']){
167 var s = warnings.length == 1 ? '' : 's';
168 log.warning("Package has ${warnings.length} warning$s.");
169 return new Future.immediate(false);
Bob Nystrom 2013/02/12 01:00:41 You don't need Future here, just "return false;"
keertip 2013/02/12 05:20:20 Done.
170 }
171
161 var message = 'Looks great! Are you ready to upload your package'; 172 var message = 'Looks great! Are you ready to upload your package';
162 173
163 if (!warnings.isEmpty) { 174 if (!warnings.isEmpty) {
164 var s = warnings.length == 1 ? '' : 's'; 175 var s = warnings.length == 1 ? '' : 's';
165 message = "Package has ${warnings.length} warning$s. Upload anyway"; 176 message = "Package has ${warnings.length} warning$s. Upload anyway";
166 } 177 }
167 178
168 return confirm(message).then((confirmed) { 179 return confirm(message).then((confirmed) {
169 if (!confirmed) throw "Package upload canceled."; 180 if (!confirmed) throw "Package upload canceled.";
Bob Nystrom 2013/02/12 01:00:41 Instead of throwing here, do log.message() then re
keertip 2013/02/12 05:20:20 Done.
181 return new Future.immediate(true);
Bob Nystrom 2013/02/12 01:00:41 Just "return true".
keertip 2013/02/12 05:20:20 Done.
170 }); 182 });
171 }); 183 });
172 } 184 }
173 } 185 }
OLDNEW
« no previous file with comments | « no previous file | utils/tests/pub/pub_lish_test.dart » ('j') | utils/tests/pub/pub_lish_test.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698