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

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

Issue 10421026: Make pub handle missing git more gracefully. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 7 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) 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('io.dart'); 10 #import('io.dart');
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 } 72 }
73 73
74 var cache = new SystemCache(cacheDir); 74 var cache = new SystemCache(cacheDir);
75 cache.sources.register(new SdkSource(sdkDir)); 75 cache.sources.register(new SdkSource(sdkDir));
76 cache.sources.register(new GitSource()); 76 cache.sources.register(new GitSource());
77 cache.sources.setDefault('sdk'); 77 cache.sources.setDefault('sdk');
78 78
79 // Select the command. 79 // Select the command.
80 var command = commands[args[0]]; 80 var command = commands[args[0]];
81 if (command == null) { 81 if (command == null) {
82 print('Unknown command "${args[0]}".'); 82 printError('Unknown command "${args[0]}".');
83 print('Run "pub help" to see available commands.'); 83 printError('Run "pub help" to see available commands.');
84 exit(64); // See http://www.freebsd.org/cgi/man.cgi?query=sysexits. 84 exit(64); // See http://www.freebsd.org/cgi/man.cgi?query=sysexits.
85 return; 85 return;
86 } 86 }
87 87
88 args.removeRange(0, 1); 88 args.removeRange(0, 1);
89 command.run(cache, args); 89 command.run(cache, args);
90 } 90 }
91 91
92 /** Displays usage information for the app. */ 92 /** Displays usage information for the app. */
93 void printUsage(Map<String, PubCommand> commands) { 93 void printUsage(Map<String, PubCommand> commands) {
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 132
133 void run(SystemCache cache_, List<String> args) { 133 void run(SystemCache cache_, List<String> args) {
134 cache = cache_; 134 cache = cache_;
135 135
136 // TODO(rnystrom): Each command should define the arguments it expects and 136 // TODO(rnystrom): Each command should define the arguments it expects and
137 // we can handle them generically here. 137 // we can handle them generically here.
138 138
139 // TODO(rnystrom): Will eventually need better logic to walk up 139 // TODO(rnystrom): Will eventually need better logic to walk up
140 // subdirectories until we hit one that looks package-like. For now, just 140 // subdirectories until we hit one that looks package-like. For now, just
141 // assume the cwd is it. 141 // assume the cwd is it.
142 Package.load(workingDir, cache.sources).then((package) { 142 var future = Package.load(workingDir, cache.sources).chain((package) {
nweiz 2012/05/23 00:46:26 No reason to assign this future to a var; you can
Bob Nystrom 2012/05/23 16:32:33 Done.
143 entrypoint = new Entrypoint(package, cache); 143 entrypoint = new Entrypoint(package, cache);
144 onRun(); 144 var commandFuture = onRun();
145 if (commandFuture == null) return new Future.immediate(true);
146
147 return commandFuture;
148 });
149
150 // This is basically the top-level exception handler so that we don't
151 // spew a stack trace on our users.
152 future.handleException((error) {
153 var message = error.toString();
nweiz 2012/05/23 00:46:26 We should probably have a --trace flag or somethin
Bob Nystrom 2012/05/23 16:32:33 Added TODO.
154
155 // TODO(rnystrom): The default exception implementation class puts
156 // "Exception:" in the output, so strip that off.
157 if (message.startsWith("Exception: ")) {
158 message = message.substring("Exception: ".length);
159 }
160
161 printError(message);
162 return true;
145 }); 163 });
146 } 164 }
147 165
148 abstract void onRun(); 166 /**
167 * Override this to perform the specific command. Return a future that
168 * completes when the command is done or fails if the command fails. If the
169 * command is synchronous, it may return `null`.
nweiz 2012/05/23 00:46:26 What if a synchronous command has an error?
Bob Nystrom 2012/05/23 16:32:33 Good call. Added try block around onRun().
170 */
171 abstract Future onRun();
149 } 172 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698