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_activate; | 5 library pub.command.global_activate; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 | 8 |
9 import '../command.dart'; | 9 import '../command.dart'; |
10 import '../utils.dart'; | 10 import '../utils.dart'; |
11 import '../version.dart'; | 11 import '../version.dart'; |
12 | 12 |
13 /// Handles the `global activate` pub command. | 13 /// Handles the `global activate` pub command. |
14 class GlobalActivateCommand extends PubCommand { | 14 class GlobalActivateCommand extends PubCommand { |
15 String get description => "Make a package's executables globally available."; | 15 String get description => "Make a package's executables globally available."; |
16 String get usage => "pub global activate <package...>"; | 16 String get usage => "pub global activate <package...>"; |
17 bool get takesArguments => true; | 17 bool get takesArguments => true; |
18 | 18 |
19 GlobalActivateCommand() { | 19 GlobalActivateCommand() { |
20 commandParser.addOption("source", | 20 commandParser.addOption("source", |
21 abbr: "s", | 21 abbr: "s", |
22 help: "The source used to find the package.", | 22 help: "The source used to find the package.", |
23 allowed: ["hosted", "path"], | 23 allowed: ["git", "hosted", "path"], |
24 defaultsTo: "hosted"); | 24 defaultsTo: "hosted"); |
25 } | 25 } |
26 | 26 |
27 Future onRun() { | 27 Future onRun() { |
28 var args = commandOptions.rest; | 28 var args = commandOptions.rest; |
29 | 29 |
30 readArg([String error]) { | 30 readArg([String error]) { |
31 if (args.isEmpty) usageError(error); | 31 if (args.isEmpty) usageError(error); |
32 var arg = args.first; | 32 var arg = args.first; |
33 args = args.skip(1); | 33 args = args.skip(1); |
34 return arg; | 34 return arg; |
35 } | 35 } |
36 | 36 |
37 validateNoExtraArgs() { | 37 validateNoExtraArgs() { |
38 if (args.isEmpty) return; | 38 if (args.isEmpty) return; |
39 var unexpected = args.map((arg) => '"$arg"'); | 39 var unexpected = args.map((arg) => '"$arg"'); |
40 var arguments = pluralize("argument", unexpected.length); | 40 var arguments = pluralize("argument", unexpected.length); |
41 usageError("Unexpected $arguments ${toSentence(unexpected)}."); | 41 usageError("Unexpected $arguments ${toSentence(unexpected)}."); |
42 } | 42 } |
43 | 43 |
44 var package = readArg("No package to activate given."); | 44 switch (commandOptions["source"]) { |
| 45 case "git": |
| 46 var repo = readArg("No Git repository given."); |
| 47 // TODO(rnystrom): Allow passing in a Git ref too. |
| 48 validateNoExtraArgs(); |
| 49 return globals.activateGit(repo); |
45 | 50 |
46 switch (commandOptions["source"]) { | |
47 case "hosted": | 51 case "hosted": |
| 52 var package = readArg("No package to activate given."); |
| 53 |
48 // Parse the version constraint, if there is one. | 54 // Parse the version constraint, if there is one. |
49 var constraint = VersionConstraint.any; | 55 var constraint = VersionConstraint.any; |
50 if (args.isNotEmpty) { | 56 if (args.isNotEmpty) { |
51 try { | 57 try { |
52 constraint = new VersionConstraint.parse(readArg()); | 58 constraint = new VersionConstraint.parse(readArg()); |
53 } on FormatException catch (error) { | 59 } on FormatException catch (error) { |
54 usageError(error.message); | 60 usageError(error.message); |
55 } | 61 } |
56 } | 62 } |
57 | 63 |
58 validateNoExtraArgs(); | 64 validateNoExtraArgs(); |
59 return globals.activateHosted(package, constraint); | 65 return globals.activateHosted(package, constraint); |
60 | 66 |
61 case "path": | 67 case "path": |
| 68 var path = readArg("No package to activate given."); |
62 validateNoExtraArgs(); | 69 validateNoExtraArgs(); |
63 return globals.activatePath(package); | 70 return globals.activatePath(path); |
64 } | 71 } |
65 | 72 |
66 throw "unreachable"; | 73 throw "unreachable"; |
67 } | 74 } |
68 } | 75 } |
OLD | NEW |