Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 library pub.command.run; | 5 library pub.command.run; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import '../command.dart'; | 9 import '../command.dart'; |
| 10 import '../executable.dart'; | 10 import '../executable.dart'; |
| 11 import '../io.dart'; | 11 import '../io.dart'; |
| 12 import '../utils.dart'; | 12 import '../utils.dart'; |
| 13 | 13 |
| 14 /// Handles the `run` pub command. | 14 /// Handles the `run` pub command. |
| 15 class RunCommand extends PubCommand { | 15 class RunCommand extends PubCommand { |
| 16 bool get takesArguments => true; | 16 bool get takesArguments => true; |
| 17 bool get allowTrailingOptions => false; | 17 bool get allowTrailingOptions => false; |
| 18 String get description => "Run an executable from a package.\n" | 18 String get description => "Run an executable from a package.\n" |
| 19 "NOTE: We are currently optimizing this command's startup time."; | 19 "NOTE: We are currently optimizing this command's startup time."; |
| 20 String get usage => "pub run <executable> [args...]"; | 20 String get usage => "pub run <executable> [args...]"; |
| 21 | 21 |
| 22 Future onRun() { | 22 Future onRun() async { |
| 23 if (commandOptions.rest.isEmpty) { | 23 if (commandOptions.rest.isEmpty) { |
| 24 usageError("Must specify an executable to run."); | 24 usageError("Must specify an executable to run."); |
| 25 } | 25 } |
| 26 | 26 |
| 27 var package = entrypoint.root.name; | 27 var package = entrypoint.root.name; |
| 28 var executable = commandOptions.rest[0]; | 28 var executable = commandOptions.rest[0]; |
| 29 var args = commandOptions.rest.skip(1).toList(); | 29 var args = commandOptions.rest.skip(1).toList(); |
| 30 | 30 |
| 31 // A command like "foo:bar" runs the "bar" script from the "foo" package. | 31 // A command like "foo:bar" runs the "bar" script from the "foo" package. |
| 32 // If there is no colon prefix, default to the root package. | 32 // If there is no colon prefix, default to the root package. |
| 33 if (executable.contains(":")) { | 33 if (executable.contains(":")) { |
| 34 var components = split1(executable, ":"); | 34 var components = split1(executable, ":"); |
| 35 package = components[0]; | 35 package = components[0]; |
| 36 executable = components[1]; | 36 executable = components[1]; |
| 37 } | 37 } |
| 38 | 38 |
| 39 return runExecutable(this, entrypoint, package, executable, args) | 39 var exitCode = await runExecutable(this, entrypoint, package, executable, |
| 40 .then(flushThenExit); | 40 args); |
| 41 flushThenExit(exitCode); | |
|
nweiz
2014/08/27 20:10:07
We should await on this.
Bob Nystrom
2014/08/27 21:35:32
Done.
| |
| 41 } | 42 } |
| 42 } | 43 } |
| OLD | NEW |