Skip to content

Commit ac25dc7

Browse files
committed
refactor(install): Allow per-crate versions in the API
1 parent dd53196 commit ac25dc7

File tree

2 files changed

+10
-16
lines changed

2 files changed

+10
-16
lines changed

src/bin/cargo/commands/install.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,11 @@ pub fn exec(config: &mut Config, args: &ArgMatches) -> CliResult {
9797
// but not `Config::reload_rooted_at` which is always cwd)
9898
let path = path.map(|p| paths::normalize_path(&p));
9999

100+
let version = args.value_of("version");
100101
let krates = args
101102
.values_of("crate")
102103
.unwrap_or_default()
104+
.map(|k| (k, version))
103105
.collect::<Vec<_>>();
104106

105107
let mut from_cwd = false;
@@ -129,7 +131,6 @@ pub fn exec(config: &mut Config, args: &ArgMatches) -> CliResult {
129131
SourceId::crates_io(config)?
130132
};
131133

132-
let version = args.value_of("version");
133134
let root = args.value_of("root");
134135

135136
// We only provide workspace information for local crate installation from
@@ -166,7 +167,6 @@ pub fn exec(config: &mut Config, args: &ArgMatches) -> CliResult {
166167
krates,
167168
source,
168169
from_cwd,
169-
version,
170170
&compile_opts,
171171
args.is_present("force"),
172172
args.is_present("no-track"),

src/cargo/ops/cargo_install.rs

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -556,10 +556,9 @@ impl<'cfg, 'a> InstallablePackage<'cfg, 'a> {
556556
pub fn install(
557557
config: &Config,
558558
root: Option<&str>,
559-
krates: Vec<&str>,
559+
krates: Vec<(&str, Option<&str>)>,
560560
source_id: SourceId,
561561
from_cwd: bool,
562-
vers: Option<&str>,
563562
opts: &ops::CompileOptions,
564563
force: bool,
565564
no_track: bool,
@@ -569,18 +568,13 @@ pub fn install(
569568
let map = SourceConfigMap::new(config)?;
570569

571570
let (installed_anything, scheduled_error) = if krates.len() <= 1 {
571+
let (krate, vers) = krates
572+
.into_iter()
573+
.next()
574+
.map(|(k, v)| (Some(k), v))
575+
.unwrap_or((None, None));
572576
let installable_pkg = InstallablePackage::new(
573-
config,
574-
root,
575-
map,
576-
krates.into_iter().next(),
577-
source_id,
578-
from_cwd,
579-
vers,
580-
opts,
581-
force,
582-
no_track,
583-
true,
577+
config, root, map, krate, source_id, from_cwd, vers, opts, force, no_track, true,
584578
)?;
585579
let mut installed_anything = true;
586580
if let Some(installable_pkg) = installable_pkg {
@@ -596,7 +590,7 @@ pub fn install(
596590

597591
let pkgs_to_install: Vec<_> = krates
598592
.into_iter()
599-
.filter_map(|krate| {
593+
.filter_map(|(krate, vers)| {
600594
let root = root.clone();
601595
let map = map.clone();
602596
match InstallablePackage::new(

0 commit comments

Comments
 (0)