Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(308)

Side by Side Diff: lib/src/command/cache_add.dart

Issue 1528523003: Clean up the semantics of package descriptions. (Closed) Base URL: git@github.com:dart-lang/pub.git@master
Patch Set: Code review changes Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | lib/src/entrypoint.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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.cache_add; 5 library pub.command.cache_add;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import 'package:pub_semver/pub_semver.dart'; 9 import 'package:pub_semver/pub_semver.dart';
10 10
11 import '../command.dart'; 11 import '../command.dart';
12 import '../log.dart' as log; 12 import '../log.dart' as log;
13 import '../package.dart'; 13 import '../source/hosted.dart';
14 import '../utils.dart'; 14 import '../utils.dart';
15 15
16 /// Handles the `cache add` pub command. 16 /// Handles the `cache add` pub command.
17 class CacheAddCommand extends PubCommand { 17 class CacheAddCommand extends PubCommand {
18 String get name => "add"; 18 String get name => "add";
19 String get description => "Install a package."; 19 String get description => "Install a package.";
20 String get invocation => 20 String get invocation =>
21 "pub cache add <package> [--version <constraint>] [--all]"; 21 "pub cache add <package> [--version <constraint>] [--all]";
22 String get docUrl => "http://dartlang.org/tools/pub/cmd/pub-cache.html"; 22 String get docUrl => "http://dartlang.org/tools/pub/cmd/pub-cache.html";
23 23
(...skipping 28 matching lines...) Expand all
52 constraint = new VersionConstraint.parse(argResults["version"]); 52 constraint = new VersionConstraint.parse(argResults["version"]);
53 } on FormatException catch (error) { 53 } on FormatException catch (error) {
54 usageException(error.message); 54 usageException(error.message);
55 } 55 }
56 } 56 }
57 57
58 // TODO(rnystrom): Support installing from git too. 58 // TODO(rnystrom): Support installing from git too.
59 var source = cache.sources["hosted"]; 59 var source = cache.sources["hosted"];
60 60
61 // TODO(rnystrom): Allow specifying the server. 61 // TODO(rnystrom): Allow specifying the server.
62 var ids = await source.getVersions( 62 var ids = (await source.getVersions(HostedSource.refFor(package)))
63 new PackageRef(package, 'hosted', package)); 63 .where((id) => constraint.allows(id.version))
64 var versions = ids.map((id) => id.version) 64 .toList();
65 .where(constraint.allows).toList();
66 65
67 if (versions.isEmpty) { 66 if (ids.isEmpty) {
68 // TODO(rnystrom): Show most recent unmatching version? 67 // TODO(rnystrom): Show most recent unmatching version?
69 fail("Package $package has no versions that match $constraint."); 68 fail("Package $package has no versions that match $constraint.");
70 } 69 }
71 70
72 downloadVersion(version) async { 71 downloadVersion(id) async {
73 var id = new PackageId(package, source.name, version, package);
74 if (cache.contains(id)) { 72 if (cache.contains(id)) {
75 // TODO(rnystrom): Include source and description if not hosted. 73 // TODO(rnystrom): Include source and description if not hosted.
76 // See solve_report.dart for code to harvest. 74 // See solve_report.dart for code to harvest.
77 log.message("Already cached ${id.name} ${id.version}."); 75 log.message("Already cached ${id.name} ${id.version}.");
78 return null; 76 return null;
79 } 77 }
80 78
81 // Download it. 79 // Download it.
82 await source.downloadToSystemCache(id); 80 await source.downloadToSystemCache(id);
83 } 81 }
84 82
85 if (argResults["all"]) { 83 if (argResults["all"]) {
86 // Install them in ascending order. 84 // Install them in ascending order.
87 versions.sort(); 85 ids.sort((id1, id2) => id1.version.compareTo(id2.version));
88 await Future.forEach(versions, downloadVersion); 86 await Future.forEach(ids, downloadVersion);
89 } else { 87 } else {
90 // Pick the best matching version. 88 // Pick the best matching version.
91 versions.sort(Version.prioritize); 89 ids.sort((id1, id2) => Version.prioritize(id1.version, id2.version));
92 await downloadVersion(versions.last); 90 await downloadVersion(ids.last);
93 } 91 }
94 } 92 }
95 } 93 }
OLDNEW
« no previous file with comments | « no previous file | lib/src/entrypoint.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698