Chromium Code Reviews| Index: utils/pub/pub.dart |
| diff --git a/utils/pub/pub.dart b/utils/pub/pub.dart |
| index 1bd1a40e543f8c3239dc786368cd08bd603f5eac..92cc62af4bf7129a68ddf40b2d314670c6b7241a 100644 |
| --- a/utils/pub/pub.dart |
| +++ b/utils/pub/pub.dart |
| @@ -17,6 +17,7 @@ |
| #import('command_update.dart'); |
| #import('command_version.dart'); |
| #import('entrypoint.dart'); |
| +#import('exit_codes.dart', prefix: 'exit_codes'); |
| #import('git_source.dart'); |
| #import('hosted_source.dart'); |
| #import('package.dart'); |
| @@ -96,7 +97,7 @@ main() { |
| if (command == null) { |
| printError('Unknown command "${globalOptions.rest[0]}".'); |
| printError('Run "pub help" to see available commands.'); |
| - exit(64); // See http://www.freebsd.org/cgi/man.cgi?query=sysexits. |
| + exit(exit_codes.USAGE); |
| return; |
| } |
| @@ -176,7 +177,7 @@ class PubCommand { |
| commandOptions = commandParser.parse(commandArgs); |
| } on FormatException catch (e) { |
| this.printUsage(description: e.message); |
| - return; |
| + exit(exit_codes.USAGE); |
| } |
| handleError(error, trace) { |
| @@ -195,9 +196,7 @@ class PubCommand { |
| printError(trace); |
| } |
| - // TODO(nweiz): Use the more semantic error codes in |
| - // http://www.freebsd.org/cgi/man.cgi?query=sysexits |
| - exit(1); |
| + exit(_exitCode(error)); |
| } |
| var future = new Future.immediate(null); |
| @@ -258,4 +257,17 @@ class PubCommand { |
| print(commandUsage); |
| } |
| } |
| + |
| + /// Returns the appropriate exit code for [exception], falling back on 1 if no |
| + /// appropriate exit code could be found. |
| + int _exitCode(exception) { |
|
Bob Nystrom
2012/09/19 18:27:42
How about a nice verby name like _chooseExitCode?
nweiz
2012/09/19 18:33:56
Done.
|
| + if (exception is HttpException || exception is HttpParserException || |
| + exception is SocketIOException || exception is PubHttpException) { |
| + return exit_codes.UNAVAILABLE; |
| + } else if (exception is FormatException) { |
| + return exit_codes.DATA; |
| + } else { |
| + return 1; |
| + } |
| + } |
| } |