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 import 'dart:async'; | 5 import 'dart:async'; |
6 | 6 |
7 import 'package:pub_semver/pub_semver.dart'; | 7 import 'package:pub_semver/pub_semver.dart'; |
8 | 8 |
9 import '../command.dart'; | 9 import '../command.dart'; |
10 import '../log.dart' as log; | 10 import '../log.dart' as log; |
11 import '../source/hosted.dart'; | |
12 import '../utils.dart'; | 11 import '../utils.dart'; |
13 | 12 |
14 /// Handles the `cache add` pub command. | 13 /// Handles the `cache add` pub command. |
15 class CacheAddCommand extends PubCommand { | 14 class CacheAddCommand extends PubCommand { |
16 String get name => "add"; | 15 String get name => "add"; |
17 String get description => "Install a package."; | 16 String get description => "Install a package."; |
18 String get invocation => | 17 String get invocation => |
19 "pub cache add <package> [--version <constraint>] [--all]"; | 18 "pub cache add <package> [--version <constraint>] [--all]"; |
20 String get docUrl => "http://dartlang.org/tools/pub/cmd/pub-cache.html"; | 19 String get docUrl => "http://dartlang.org/tools/pub/cmd/pub-cache.html"; |
21 | 20 |
(...skipping 25 matching lines...) Expand all Loading... |
47 var constraint = VersionConstraint.any; | 46 var constraint = VersionConstraint.any; |
48 if (argResults["version"] != null) { | 47 if (argResults["version"] != null) { |
49 try { | 48 try { |
50 constraint = new VersionConstraint.parse(argResults["version"]); | 49 constraint = new VersionConstraint.parse(argResults["version"]); |
51 } on FormatException catch (error) { | 50 } on FormatException catch (error) { |
52 usageException(error.message); | 51 usageException(error.message); |
53 } | 52 } |
54 } | 53 } |
55 | 54 |
56 // TODO(rnystrom): Support installing from git too. | 55 // TODO(rnystrom): Support installing from git too. |
57 var source = cache.sources["hosted"]; | 56 var source = cache.source("hosted"); |
58 | 57 |
59 // TODO(rnystrom): Allow specifying the server. | 58 // TODO(rnystrom): Allow specifying the server. |
60 var ids = (await source.getVersions(HostedSource.refFor(package))) | 59 var ids = (await source.getVersions(cache.sources.hosted.refFor(package))) |
61 .where((id) => constraint.allows(id.version)) | 60 .where((id) => constraint.allows(id.version)) |
62 .toList(); | 61 .toList(); |
63 | 62 |
64 if (ids.isEmpty) { | 63 if (ids.isEmpty) { |
65 // TODO(rnystrom): Show most recent unmatching version? | 64 // TODO(rnystrom): Show most recent unmatching version? |
66 fail("Package $package has no versions that match $constraint."); | 65 fail("Package $package has no versions that match $constraint."); |
67 } | 66 } |
68 | 67 |
69 downloadVersion(id) async { | 68 downloadVersion(id) async { |
70 if (cache.contains(id)) { | 69 if (cache.contains(id)) { |
(...skipping 11 matching lines...) Expand all Loading... |
82 // Install them in ascending order. | 81 // Install them in ascending order. |
83 ids.sort((id1, id2) => id1.version.compareTo(id2.version)); | 82 ids.sort((id1, id2) => id1.version.compareTo(id2.version)); |
84 await Future.forEach(ids, downloadVersion); | 83 await Future.forEach(ids, downloadVersion); |
85 } else { | 84 } else { |
86 // Pick the best matching version. | 85 // Pick the best matching version. |
87 ids.sort((id1, id2) => Version.prioritize(id1.version, id2.version)); | 86 ids.sort((id1, id2) => Version.prioritize(id1.version, id2.version)); |
88 await downloadVersion(ids.last); | 87 await downloadVersion(ids.last); |
89 } | 88 } |
90 } | 89 } |
91 } | 90 } |
OLD | NEW |