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