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

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

Issue 10911085: Emit a non-zero exit code when Pub fails. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 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
« no previous file with comments | « no previous file | utils/tests/pub/pub_install_git_test.dart » ('j') | no next file with comments »
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 /** 5 /**
6 * The main entrypoint for the pub command line application. 6 * The main entrypoint for the pub command line application.
7 */ 7 */
8 #library('pub'); 8 #library('pub');
9 9
10 #import('../../pkg/args/args.dart'); 10 #import('../../pkg/args/args.dart');
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 try { 177 try {
178 commandOptions = commandParser.parse(commandArgs); 178 commandOptions = commandParser.parse(commandArgs);
179 } on FormatException catch (e) { 179 } on FormatException catch (e) {
180 this.printUsage(description: e.message); 180 this.printUsage(description: e.message);
181 return; 181 return;
182 } 182 }
183 183
184 handleError(error, trace) { 184 handleError(error, trace) {
185 // This is basically the top-level exception handler so that we don't 185 // This is basically the top-level exception handler so that we don't
186 // spew a stack trace on our users. 186 // spew a stack trace on our users.
187 // TODO(rnystrom): Add --trace flag so stack traces can be enabled for
188 // debugging.
189 var message = error.toString(); 187 var message = error.toString();
190 188
191 // TODO(rnystrom): The default exception implementation class puts 189 // TODO(rnystrom): The default exception implementation class puts
192 // "Exception:" in the output, so strip that off. 190 // "Exception:" in the output, so strip that off.
193 if (message.startsWith("Exception: ")) { 191 if (message.startsWith("Exception: ")) {
194 message = message.substring("Exception: ".length); 192 message = message.substring("Exception: ".length);
195 } 193 }
196 194
197 printError(message); 195 printError(message);
198 if (globalOptions['trace'] && trace != null) { 196 if (globalOptions['trace'] && trace != null) {
199 printError(trace); 197 printError(trace);
200 } 198 }
201 return true; 199
200 // TODO(nweiz): Use the more semantic error codes in
201 // http://www.freebsd.org/cgi/man.cgi?query=sysexits
202 exit(1);
202 } 203 }
203 204
204 // TODO(rnystrom): Will eventually need better logic to walk up 205 // TODO(rnystrom): Will eventually need better logic to walk up
205 // subdirectories until we hit one that looks package-like. For now, just 206 // subdirectories until we hit one that looks package-like. For now, just
206 // assume the cwd is it. 207 // assume the cwd is it.
207 var future = Package.load(workingDir, cache.sources).chain((package) { 208 var future = Package.load(workingDir, cache.sources).chain((package) {
208 entrypoint = new Entrypoint(package, cache); 209 entrypoint = new Entrypoint(package, cache);
209 210
210 try { 211 try {
211 var commandFuture = onRun(); 212 var commandFuture = onRun();
212 if (commandFuture == null) return new Future.immediate(true); 213 if (commandFuture == null) return new Future.immediate(true);
213 214
214 return commandFuture; 215 return commandFuture;
215 } catch (error, trace) { 216 } catch (error, trace) {
216 handleError(error, trace); 217 handleError(error, trace);
217 return new Future.immediate(null); 218 return new Future.immediate(null);
218 } 219 }
219 }); 220 });
220 future.handleException((e) => handleError(e, future.stackTrace)); 221 future.handleException((e) => handleError(e, future.stackTrace));
222 future.then((_) => exit(0));
Bob Nystrom 2012/09/05 00:52:00 Can you add a comment here saying this is success
nweiz 2012/09/05 00:59:19 Done.
221 } 223 }
222 224
223 /** 225 /**
224 * Override this to perform the specific command. Return a future that 226 * Override this to perform the specific command. Return a future that
225 * completes when the command is done or fails if the command fails. If the 227 * completes when the command is done or fails if the command fails. If the
226 * command is synchronous, it may return `null`. 228 * command is synchronous, it may return `null`.
227 */ 229 */
228 abstract Future onRun(); 230 abstract Future onRun();
229 231
230 /** Displays usage information for this command. */ 232 /** Displays usage information for this command. */
231 void printUsage([String description]) { 233 void printUsage([String description]) {
232 if (description == null) description = this.description; 234 if (description == null) description = this.description;
233 print(description); 235 print(description);
234 print(''); 236 print('');
235 print('Usage: $usage'); 237 print('Usage: $usage');
236 238
237 var commandUsage = commandParser.getUsage(); 239 var commandUsage = commandParser.getUsage();
238 if (!commandUsage.isEmpty()) { 240 if (!commandUsage.isEmpty()) {
239 print(''); 241 print('');
240 print(commandUsage); 242 print(commandUsage);
241 } 243 }
242 } 244 }
243 } 245 }
OLDNEW
« no previous file with comments | « no previous file | utils/tests/pub/pub_install_git_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698