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.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 '../executable.dart'; |
| 14 import '../io.dart'; |
| 15 import '../utils.dart'; |
| 16 |
| 17 /// Handles the `run` pub command. |
| 18 class RunCommand extends PubCommand { |
| 19 String get name => "run"; |
| 20 String get description => |
| 21 "Run an executable from a package.\n" |
| 22 "NOTE: We are currently optimizing this command's startup time."; |
| 23 String get invocation => "pub run <executable> [args...]"; |
| 24 bool get allowTrailingOptions => false; |
| 25 |
| 26 RunCommand() { |
| 27 argParser.addOption( |
| 28 "mode", |
| 29 help: 'Mode to run transformers in.\n' |
| 30 '(defaults to "release" for dependencies, "debug" for ' 'entrypoint)
'); |
| 31 } |
| 32 |
| 33 Future run() { |
| 34 final completer0 = new Completer(); |
| 35 scheduleMicrotask(() { |
| 36 try { |
| 37 join0() { |
| 38 var package = entrypoint.root.name; |
| 39 var executable = argResults.rest[0]; |
| 40 var args = argResults.rest.skip(1).toList(); |
| 41 join1() { |
| 42 var mode; |
| 43 join2() { |
| 44 new Future.value( |
| 45 runExecutable(entrypoint, package, executable, args, mode: mod
e)).then((x0) { |
| 46 try { |
| 47 var exitCode = x0; |
| 48 new Future.value(flushThenExit(exitCode)).then((x1) { |
| 49 try { |
| 50 x1; |
| 51 completer0.complete(); |
| 52 } catch (e0, s0) { |
| 53 completer0.completeError(e0, s0); |
| 54 } |
| 55 }, onError: completer0.completeError); |
| 56 } catch (e1, s1) { |
| 57 completer0.completeError(e1, s1); |
| 58 } |
| 59 }, onError: completer0.completeError); |
| 60 } |
| 61 if (argResults['mode'] != null) { |
| 62 mode = new BarbackMode(argResults['mode']); |
| 63 join2(); |
| 64 } else { |
| 65 join3() { |
| 66 join2(); |
| 67 } |
| 68 if (package == entrypoint.root.name) { |
| 69 mode = BarbackMode.DEBUG; |
| 70 join3(); |
| 71 } else { |
| 72 mode = BarbackMode.RELEASE; |
| 73 join3(); |
| 74 } |
| 75 } |
| 76 } |
| 77 if (executable.contains(":")) { |
| 78 var components = split1(executable, ":"); |
| 79 package = components[0]; |
| 80 executable = components[1]; |
| 81 join4() { |
| 82 join1(); |
| 83 } |
| 84 if (p.split(executable).length > 1) { |
| 85 usageException( |
| 86 "Cannot run an executable in a subdirectory of a " + "dependen
cy."); |
| 87 join4(); |
| 88 } else { |
| 89 join4(); |
| 90 } |
| 91 } else { |
| 92 join1(); |
| 93 } |
| 94 } |
| 95 if (argResults.rest.isEmpty) { |
| 96 usageException("Must specify an executable to run."); |
| 97 join0(); |
| 98 } else { |
| 99 join0(); |
| 100 } |
| 101 } catch (e, s) { |
| 102 completer0.completeError(e, s); |
| 103 } |
| 104 }); |
| 105 return completer0.future; |
| 106 } |
| 107 } |
OLD | NEW |