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 command_cache; | 5 library command_cache; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'dart:io'; | 8 import 'dart:io'; |
9 import 'dart:json' as json; | 9 import 'dart:json' as json; |
10 | 10 |
11 import 'exit_codes.dart' as exit_codes; | 11 import 'exit_codes.dart' as exit_codes; |
12 import 'log.dart' as log; | 12 import 'log.dart' as log; |
13 import 'pub.dart'; | 13 import 'pub.dart'; |
14 | 14 |
15 | 15 |
16 /// Handles the `cache` pub command. | 16 /// Handles the `cache` pub command. |
17 class CacheCommand extends PubCommand { | 17 class CacheCommand extends PubCommand { |
18 String get description => "Inspect the system cache."; | 18 String get description => "Inspect the system cache."; |
19 String get usage => 'pub cache list'; | 19 String get usage => 'pub cache list'; |
20 bool get requiresEntrypoint => false; | 20 bool get requiresEntrypoint => false; |
21 | 21 |
22 Future onRun() { | 22 Future onRun() { |
23 if (commandOptions.rest.length != 1) { | 23 if (commandOptions.rest.length != 1) { |
24 log.error('The cache command expects one argument.'); | 24 log.error('The cache command expects one argument.'); |
25 this.printUsage(); | 25 this.printUsage(); |
26 exit(exit_codes.USAGE); | 26 exit(exit_codes.USAGE); |
27 } | 27 } |
28 | 28 |
29 if ((commandOptions.rest[0] != 'list')) { | 29 if ((commandOptions.rest[0] != 'list')) { |
30 log.error('Unknown cache command "${commandOptions.rest[0]}".'); | 30 log.error('Unknown cache command "${commandOptions.rest[0]}".'); |
31 this.printUsage(); | 31 this.printUsage(); |
32 exit(exit_codes.USAGE); | 32 exit(exit_codes.USAGE); |
33 } | 33 } |
34 | 34 |
35 // TODO(keertip): Add flag to list packages from non default sources | 35 // TODO(keertip): Add flag to list packages from non default sources |
36 var packagesObj = <String, Map>{}; | 36 var packagesObj = <String, Map>{}; |
37 for (var package in cache.sources.defaultSource.getCachedPackages()) { | 37 for (var package in cache.sources.defaultSource.getCachedPackages()) { |
38 packagesObj[package.name] = { | 38 packagesObj[package.name] = { |
39 'version': package.version.toString(), | 39 'version': package.version.toString(), |
40 'location': package.dir | 40 'location': package.dir |
41 }; | 41 }; |
42 } | 42 } |
43 | 43 |
44 // TODO(keertip): Add support for non-JSON format | 44 // TODO(keertip): Add support for non-JSON format |
45 // and check for --format flag | 45 // and check for --format flag |
46 log.message(json.stringify({'packages': packagesObj})); | 46 log.message(json.stringify({'packages': packagesObj})); |
47 } | 47 } |
48 } | 48 } |
49 | 49 |
OLD | NEW |