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

Unified Diff: utils/pub/command_lish.dart

Issue 12217156: Add --force to pub lish. (Closed) Base URL: https://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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | utils/tests/pub/pub_lish_test.dart » ('j') | utils/tests/pub/test_pub.dart » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: utils/pub/command_lish.dart
diff --git a/utils/pub/command_lish.dart b/utils/pub/command_lish.dart
index 5cd75a038ac15ab3b735b1ad3c4df161c1a49983..d3a2cb4bf67aca21851b9a193626036be19a6081 100644
--- a/utils/pub/command_lish.dart
+++ b/utils/pub/command_lish.dart
@@ -13,6 +13,7 @@ import '../../pkg/args/lib/args.dart';
import '../../pkg/http/lib/http.dart' as http;
import '../../pkg/path/lib/path.dart' as path;
import 'directory_tree.dart';
+import 'exit_codes.dart' as exit_codes;
import 'git.dart' as git;
import 'http.dart';
import 'io.dart';
@@ -34,6 +35,8 @@ class LishCommand extends PubCommand {
// dart:io for HTTPS requests.
parser.addFlag('dry-run', abbr: 'n', negatable: false,
help: 'Validate but do not publish the package');
+ parser.addFlag('force', abbr: 'f', negatable: false,
+ help: 'Publish without confirmation if there are no errors');
parser.addOption('server', defaultsTo: 'https://pub.dartlang.org',
help: 'The package server to which to upload this package');
return parser;
@@ -42,6 +45,12 @@ class LishCommand extends PubCommand {
/// The URL of the server to which to upload the package.
Uri get server => Uri.parse(commandOptions['server']);
+ /// Whether the publish is just a preview.
+ bool get dryRun => commandOptions['dry-run'];
+
+ /// Whether the publish requires confirmation.
+ bool get force => commandOptions['force'];
+
Future _publish(packageBytes) {
var cloudStorageUrl;
return oauth2.withClient(cache, (client) {
@@ -88,6 +97,12 @@ class LishCommand extends PubCommand {
}
Future onRun() {
+ if (force && dryRun) {
+ log.error('Cannot use both --force and --dry-run.');
+ this.printUsage();
+ exit(exit_codes.USAGE);
+ }
+
var packageBytesFuture = _filesToPublish.then((files) {
log.fine('Archiving and publishing ${entrypoint.root}.');
@@ -106,7 +121,7 @@ class LishCommand extends PubCommand {
if (isValid) return packageBytesFuture.then(_publish);
});
}
-
+
/// The basenames of files that are automatically excluded from archives.
final _BLACKLISTED_FILES = const ['pubspec.lock'];
@@ -149,7 +164,8 @@ class LishCommand extends PubCommand {
invalidServerResponse(response);
}
- /// Validates the package. Throws an exception if it's invalid.
+ /// Validates the package. Completes to false if the upload should not
+ /// proceed.
Future<bool> _validate(Future<int> packageSize) {
return Validator.runAll(entrypoint, packageSize).then((pair) {
var errors = pair.first;
@@ -163,12 +179,14 @@ class LishCommand extends PubCommand {
return false;
}
- if (commandOptions['dry-run']){
+ if (force) return true;
+
+ if (dryRun) {
var s = warnings.length == 1 ? '' : 's';
log.warning("Package has ${warnings.length} warning$s.");
return false;
}
-
+
var message = 'Looks great! Are you ready to upload your package';
if (!warnings.isEmpty) {
« no previous file with comments | « no previous file | utils/tests/pub/pub_lish_test.dart » ('j') | utils/tests/pub/test_pub.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698