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.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> [version]"; | 16 String get usage => "pub global activate [--source source] <package> [version] "; |
|
nweiz
2014/07/31 20:01:53
Long line. Also, normally we don't include options
Bob Nystrom
2014/08/04 23:41:50
Tweaked it a bit.
| |
| 17 bool get takesArguments => true; | 17 bool get takesArguments => true; |
| 18 | 18 |
| 19 GlobalActivateCommand() { | |
| 20 commandParser.addOption("source", | |
| 21 abbr: "s", | |
| 22 help: "The source used to find the package.", | |
| 23 allowed: ["git", "hosted", "path"], | |
| 24 defaultsTo: "hosted"); | |
| 25 } | |
| 26 | |
| 19 Future onRun() { | 27 Future onRun() { |
| 20 // Make sure there is a package. | 28 var args = commandOptions.rest; |
| 21 if (commandOptions.rest.isEmpty) { | 29 |
| 22 usageError("No package to activate given."); | 30 readArg(String error) { |
| 31 if (args.isEmpty) usageError(error); | |
| 32 var arg = args.first; | |
| 33 args = args.skip(1); | |
| 34 return arg; | |
| 23 } | 35 } |
| 24 | 36 |
| 25 // Don't allow extra arguments. | 37 validateNoExtraArgs() { |
| 26 if (commandOptions.rest.length > 2) { | 38 if (args.isEmpty) return; |
| 27 var unexpected = commandOptions.rest.skip(2).map((arg) => '"$arg"'); | 39 var unexpected = args.map((arg) => '"$arg"'); |
| 28 var arguments = pluralize("argument", unexpected.length); | 40 var arguments = pluralize("argument", unexpected.length); |
| 29 usageError("Unexpected $arguments ${toSentence(unexpected)}."); | 41 usageError("Unexpected $arguments ${toSentence(unexpected)}."); |
| 30 } | 42 } |
| 31 | 43 |
| 32 var package = commandOptions.rest.first; | 44 var package = readArg("No package to activate given."); |
| 33 | 45 |
| 34 // Parse the version constraint, if there is one. | 46 switch (commandOptions["source"]) { |
| 35 var constraint = VersionConstraint.any; | 47 case "git": |
| 36 if (commandOptions.rest.length == 2) { | 48 // Parse the git ref. |
| 37 try { | 49 // TODO(bob): Test. |
|
nweiz
2014/07/31 20:01:53
Remove this
Bob Nystrom
2014/08/04 23:41:50
Done.
| |
| 38 constraint = new VersionConstraint.parse(commandOptions.rest[1]); | 50 var ref = readArg("Must provide a Git ref for the package."); |
|
nweiz
2014/07/31 20:01:53
Why does the user have to supply a ref for git? Gi
Bob Nystrom
2014/08/04 23:41:50
I think I just got my terminology confused here. T
| |
| 39 } on FormatException catch (error) { | 51 validateNoExtraArgs(); |
| 40 usageError(error.message); | 52 return globals.activateGit(package, ref); |
| 41 } | 53 |
| 54 case "hosted": | |
| 55 // Parse the version constraint, if there is one. | |
| 56 var constraint = VersionConstraint.any; | |
| 57 if (args.isNotEmpty) { | |
| 58 try { | |
| 59 constraint = new VersionConstraint.parse(readArg("")); | |
|
nweiz
2014/07/31 20:01:53
Passing an empty string to parseArg here reads wei
Bob Nystrom
2014/08/04 23:41:50
Done.
| |
| 60 } on FormatException catch (error) { | |
| 61 usageError(error.message); | |
| 62 } | |
| 63 } | |
| 64 | |
| 65 validateNoExtraArgs(); | |
| 66 return globals.activateHosted(package, constraint); | |
| 67 | |
| 68 case "path": | |
| 69 validateNoExtraArgs(); | |
| 70 return globals.activatePath(package); | |
| 42 } | 71 } |
| 43 | 72 |
| 44 return globals.activate(package, constraint); | 73 throw "unreachable"; |
| 45 } | 74 } |
| 46 } | 75 } |
| OLD | NEW |