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.global_run; | 5 library pub.command.global_run; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 | 8 |
9 import 'package:barback/barback.dart'; | 9 import 'package:barback/barback.dart'; |
10 import 'package:path/path.dart' as p; | 10 import 'package:path/path.dart' as p; |
11 | 11 |
12 import '../command.dart'; | 12 import '../command.dart'; |
13 import '../io.dart'; | 13 import '../io.dart'; |
14 import '../utils.dart'; | 14 import '../utils.dart'; |
15 | 15 |
16 /// Handles the `global run` pub command. | 16 /// Handles the `global run` pub command. |
17 class GlobalRunCommand extends PubCommand { | 17 class GlobalRunCommand extends PubCommand { |
18 String get name => "run"; | 18 String get name => "run"; |
19 String get description => | 19 String get description => |
20 "Run an executable from a globally activated package.\n" | 20 "Run an executable from a globally activated package.\n" |
21 "NOTE: We are currently optimizing this command's startup time."; | 21 "NOTE: We are currently optimizing this command's startup time."; |
22 String get invocation => "pub global run <package>:<executable> [args...]"; | 22 String get invocation => "pub global run <package>:<executable> [args...]"; |
23 bool get allowTrailingOptions => false; | 23 bool get allowTrailingOptions => false; |
24 | 24 |
25 /// The mode for barback transformers. | 25 /// The mode for barback transformers. |
26 BarbackMode get mode => new BarbackMode(argResults["mode"]); | 26 BarbackMode get mode => new BarbackMode(argResults["mode"]); |
27 | 27 |
28 GlobalRunCommand() { | 28 GlobalRunCommand() { |
29 argParser.addFlag("checked", abbr: "c", negatable: false, | |
nweiz
2015/08/06 00:08:28
Why not make this negatable? The VM supports --no-
Bob Nystrom
2015/08/06 16:54:42
TIL. Done.
| |
30 help: "Enable runtime type checks and assertions."); | |
29 argParser.addOption("mode", defaultsTo: "release", | 31 argParser.addOption("mode", defaultsTo: "release", |
30 help: 'Mode to run transformers in.'); | 32 help: 'Mode to run transformers in.'); |
31 } | 33 } |
32 | 34 |
33 Future run() async { | 35 Future run() async { |
34 if (argResults.rest.isEmpty) { | 36 if (argResults.rest.isEmpty) { |
35 usageException("Must specify an executable to run."); | 37 usageException("Must specify an executable to run."); |
36 } | 38 } |
37 | 39 |
38 var package; | 40 var package; |
39 var executable = argResults.rest[0]; | 41 var executable = argResults.rest[0]; |
40 if (executable.contains(":")) { | 42 if (executable.contains(":")) { |
41 var parts = split1(executable, ":"); | 43 var parts = split1(executable, ":"); |
42 package = parts[0]; | 44 package = parts[0]; |
43 executable = parts[1]; | 45 executable = parts[1]; |
44 } else { | 46 } else { |
45 // If the package name is omitted, use the same name for both. | 47 // If the package name is omitted, use the same name for both. |
46 package = executable; | 48 package = executable; |
47 } | 49 } |
48 | 50 |
49 var args = argResults.rest.skip(1).toList(); | 51 var args = argResults.rest.skip(1).toList(); |
50 if (p.split(executable).length > 1) { | 52 if (p.split(executable).length > 1) { |
51 // TODO(nweiz): Use adjacent strings when the new async/await compiler | 53 usageException('Cannot run an executable in a subdirectory of a global ' |
52 // lands. | |
53 usageException('Cannot run an executable in a subdirectory of a global ' + | |
54 'package.'); | 54 'package.'); |
55 } | 55 } |
56 | 56 |
57 var exitCode = await globals.runExecutable(package, executable, args, | 57 var exitCode = await globals.runExecutable(package, executable, args, |
58 mode: mode); | 58 checked: argResults["checked"], mode: mode); |
59 await flushThenExit(exitCode); | 59 await flushThenExit(exitCode); |
60 } | 60 } |
61 } | 61 } |
OLD | NEW |