| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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.list_package_dirs; | 5 library pub.command.list_package_dirs; |
| 6 | 6 |
| 7 import 'package:path/path.dart' as p; | 7 import 'package:path/path.dart' as p; |
| 8 | 8 |
| 9 import '../command.dart'; | 9 import '../command.dart'; |
| 10 import '../io.dart'; |
| 10 import '../log.dart' as log; | 11 import '../log.dart' as log; |
| 11 import '../utils.dart'; | 12 import '../utils.dart'; |
| 12 | 13 |
| 13 /// Handles the `list-package-dirs` pub command. | 14 /// Handles the `list-package-dirs` pub command. |
| 14 class ListPackageDirsCommand extends PubCommand { | 15 class ListPackageDirsCommand extends PubCommand { |
| 15 String get name => "list-package-dirs"; | 16 String get name => "list-package-dirs"; |
| 16 String get description => "Print local paths to dependencies."; | 17 String get description => "Print local paths to dependencies."; |
| 17 String get invocation => "pub list-package-dirs"; | 18 String get invocation => "pub list-package-dirs"; |
| 18 bool get takesArguments => false; | 19 bool get takesArguments => false; |
| 19 bool get hidden => true; | 20 bool get hidden => true; |
| 20 | 21 |
| 21 ListPackageDirsCommand() { | 22 ListPackageDirsCommand() { |
| 22 argParser.addOption("format", | 23 argParser.addOption("format", |
| 23 help: "How output should be displayed.", | 24 help: "How output should be displayed.", |
| 24 allowed: ["json"]); | 25 allowed: ["json"]); |
| 25 } | 26 } |
| 26 | 27 |
| 27 void run() { | 28 void run() { |
| 28 log.json.enabled = true; | 29 log.json.enabled = true; |
| 29 | 30 |
| 30 if (!entrypoint.lockFileExists) { | 31 if (!fileExists(entrypoint.lockFilePath)) { |
| 31 dataError('Package "myapp" has no lockfile. Please run "pub get" first.'); | 32 dataError('Package "myapp" has no lockfile. Please run "pub get" first.'); |
| 32 } | 33 } |
| 33 | 34 |
| 34 var output = {}; | 35 var output = {}; |
| 35 | 36 |
| 36 // Include the local paths to all locked packages. | 37 // Include the local paths to all locked packages. |
| 37 var packages = mapMap(entrypoint.lockFile.packages, value: (name, package) { | 38 var packages = mapMap(entrypoint.lockFile.packages, value: (name, package) { |
| 38 var source = entrypoint.cache.sources[package.source]; | 39 var source = entrypoint.cache.sources[package.source]; |
| 39 var packageDir = source.getDirectory(package); | 40 var packageDir = source.getDirectory(package); |
| 40 // Normalize paths and make them absolute for backwards compatibility | 41 // Normalize paths and make them absolute for backwards compatibility |
| (...skipping 11 matching lines...) Expand all Loading... |
| 52 // that's just the pubspec and lockfile. | 53 // that's just the pubspec and lockfile. |
| 53 output["input_files"] = [ | 54 output["input_files"] = [ |
| 54 p.normalize(p.absolute(entrypoint.lockFilePath)), | 55 p.normalize(p.absolute(entrypoint.lockFilePath)), |
| 55 p.normalize(p.absolute(entrypoint.pubspecPath)) | 56 p.normalize(p.absolute(entrypoint.pubspecPath)) |
| 56 ]; | 57 ]; |
| 57 | 58 |
| 58 log.json.message(output); | 59 log.json.message(output); |
| 59 } | 60 } |
| 60 } | 61 } |
| 61 | 62 |
| OLD | NEW |