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

Unified Diff: utils/pub/io.dart

Issue 11557008: Make pub publish more user friendly: (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Merge in path changes. Created 8 years 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 | « utils/pub/directory_tree.dart ('k') | utils/pub/path.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: utils/pub/io.dart
diff --git a/utils/pub/io.dart b/utils/pub/io.dart
index e6ea0718e57b93191cbb70ee1e158ddd2b891d08..39a854d846bd0e9181c552b00fa1ecff227a9a5a 100644
--- a/utils/pub/io.dart
+++ b/utils/pub/io.dart
@@ -446,6 +446,18 @@ String relativeToPub(String target) {
/// A StringInputStream reading from stdin.
final _stringStdin = new StringInputStream(stdin);
+/// Displays a message and reads a yes/no confirmation from the user. Returns
+/// a [Future] that completes to `true` if the user confirms or `false` if they
+/// do not.
+///
+/// This will automatically append " (y/n)?" to the message, so [message]
+/// should just be a fragment like, "Are you sure you want to proceed".
+Future<bool> confirm(String message) {
+ log.fine('Showing confirm message: $message');
+ stdout.writeString("$message (y/n)? ");
+ return readLine().transform((line) => new RegExp(r"^[yY]").hasMatch(line));
+}
+
/// Returns a single line read from a [StringInputStream]. By default, reads
/// from stdin.
///
@@ -475,7 +487,9 @@ Future<String> readLine([StringInputStream stream]) {
stream.onLine = () {
removeCallbacks();
- completer.complete(stream.readLine());
+ var line = stream.readLine();
+ log.io('Read line: $line');
+ completer.complete(line);
};
stream.onError = (e) {
@@ -929,7 +943,7 @@ Future<bool> _extractTarGzWindows(InputStream stream, String destination) {
InputStream createTarGz(List contents, {baseDir}) {
var buffer = new StringBuffer();
buffer.add('Creating .tag.gz stream containing:\n');
- contents.forEach(buffer.add);
+ contents.forEach((file) => buffer.add('$file\n'));
log.fine(buffer.toString());
// TODO(nweiz): Propagate errors to the returned stream (including non-zero
« no previous file with comments | « utils/pub/directory_tree.dart ('k') | utils/pub/path.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698