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

Side by Side Diff: sdk/lib/_internal/pub/bin/pub.dart

Issue 521643005: Convert more pub code to use async/await. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Revise! Created 6 years, 3 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
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 import 'dart:async'; 5 import 'dart:async';
6 import 'dart:io'; 6 import 'dart:io';
7 7
8 import 'package:args/args.dart'; 8 import 'package:args/args.dart';
9 import 'package:http/http.dart' as http; 9 import 'package:http/http.dart' as http;
10 import 'package:path/path.dart' as path; 10 import 'package:path/path.dart' as path;
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 } else if (exception is FormatException || exception is DataException) { 122 } else if (exception is FormatException || exception is DataException) {
123 return exit_codes.DATA; 123 return exit_codes.DATA;
124 } else if (exception is UsageException) { 124 } else if (exception is UsageException) {
125 return exit_codes.USAGE; 125 return exit_codes.USAGE;
126 } else { 126 } else {
127 return 1; 127 return 1;
128 } 128 }
129 } 129 }
130 130
131 /// Walks the command tree and runs the selected pub command. 131 /// Walks the command tree and runs the selected pub command.
132 Future invokeCommand(String cacheDir, ArgResults mainOptions) { 132 Future invokeCommand(String cacheDir, ArgResults mainOptions) async {
133 var commands = PubCommand.mainCommands; 133 var commands = PubCommand.mainCommands;
134 var command; 134 var command;
135 var commandString = "pub"; 135 var commandString = "pub";
136 var options = mainOptions; 136 var options = mainOptions;
137 137
138 while (commands.isNotEmpty) { 138 while (commands.isNotEmpty) {
139 if (options.command == null) { 139 if (options.command == null) {
140 if (options.rest.isEmpty) { 140 if (options.rest.isEmpty) {
141 if (command == null) { 141 if (command == null) {
142 // No top-level command was chosen. 142 // No top-level command was chosen.
(...skipping 24 matching lines...) Expand all
167 return new Future.value(); 167 return new Future.value();
168 } 168 }
169 } 169 }
170 170
171 // Make sure there aren't unexpected arguments. 171 // Make sure there aren't unexpected arguments.
172 if (!command.takesArguments && options.rest.isNotEmpty) { 172 if (!command.takesArguments && options.rest.isNotEmpty) {
173 command.usageError( 173 command.usageError(
174 'Command "${options.name}" does not take any arguments.'); 174 'Command "${options.name}" does not take any arguments.');
175 } 175 }
176 176
177 return syncFuture(() { 177 try {
178 // TODO(rnystrom): Use await here when this is fixed:
179 // https://github.com/dart-lang/async_await/issues/40.
178 return command.run(cacheDir, mainOptions, options); 180 return command.run(cacheDir, mainOptions, options);
179 }).whenComplete(() { 181 } finally {
180 command.cache.deleteTempDir(); 182 command.cache.deleteTempDir();
181 }); 183 }
182 } 184 }
183 185
184 /// Checks that pub is running on a supported platform. 186 /// Checks that pub is running on a supported platform.
185 /// 187 ///
186 /// If it isn't, it prints an error message and exits. Completes when the 188 /// If it isn't, it prints an error message and exits. Completes when the
187 /// validation is done. 189 /// validation is done.
188 Future validatePlatform() { 190 Future validatePlatform() async {
189 return syncFuture(() { 191 if (Platform.operatingSystem != 'windows') return;
190 if (Platform.operatingSystem != 'windows') return null;
191 192
192 return runProcess('ver', []).then((result) { 193 var result = await runProcess('ver', []);
193 if (result.stdout.join('\n').contains('XP')) { 194 if (result.stdout.join('\n').contains('XP')) {
194 log.error('Sorry, but pub is not supported on Windows XP.'); 195 log.error('Sorry, but pub is not supported on Windows XP.');
195 return flushThenExit(exit_codes.USAGE); 196 await flushThenExit(exit_codes.USAGE);
196 } 197 }
197 });
198 });
199 } 198 }
OLDNEW
« no previous file with comments | « sdk/lib/_internal/pub/bin/async_compile.dart ('k') | sdk/lib/_internal/pub/lib/src/command/cache_repair.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698