Skip to content

Commit 66168ac

Browse files
Paul Woolcockdurka
authored andcommitted
old commit adding some support for multi-install
1 parent 534ce68 commit 66168ac

File tree

2 files changed

+44
-6
lines changed

2 files changed

+44
-6
lines changed

src/bin/install.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ pub struct Options {
2222
flag_frozen: bool,
2323
flag_locked: bool,
2424

25-
arg_crate: Option<String>,
25+
arg_crate: Vec<String>,
2626
flag_vers: Option<String>,
2727

2828
flag_git: Option<String>,
@@ -37,7 +37,7 @@ pub const USAGE: &'static str = "
3737
Install a Rust binary
3838
3939
Usage:
40-
cargo install [options] [<crate>]
40+
cargo install [options] [<crate>...]
4141
cargo install [options] --list
4242
4343
Specifying what crate to install:
@@ -139,20 +139,20 @@ pub fn execute(options: Options, config: &Config) -> CliResult {
139139
SourceId::for_git(&url, gitref)
140140
} else if let Some(path) = options.flag_path {
141141
SourceId::for_path(&config.cwd().join(path))?
142-
} else if options.arg_crate == None {
142+
} else if options.arg_crate.is_empty() {
143143
SourceId::for_path(&config.cwd())?
144144
} else {
145145
SourceId::crates_io(config)?
146146
};
147147

148-
let krate = options.arg_crate.as_ref().map(|s| &s[..]);
148+
let krates = options.arg_crate.iter().map(|s| &s[..]).collect::<Vec<_>>();
149149
let vers = options.flag_vers.as_ref().map(|s| &s[..]);
150150
let root = options.flag_root.as_ref().map(|s| &s[..]);
151151

152152
if options.flag_list {
153153
ops::install_list(root, config)?;
154154
} else {
155-
ops::install(root, krate, &source, vers, &compile_opts, options.flag_force)?;
155+
ops::install(root, krates, &source, vers, &compile_opts, options.flag_force)?;
156156
}
157157
Ok(())
158158
}

tests/install.rs

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,45 @@ warning: be sure to add `[..]` to your PATH to be able to run the installed bina
5555
}
5656

5757
#[test]
58-
fn pick_max_version() {
58+
test!(multiple_pkgs {
59+
pkg("foo", "0.0.1");
60+
pkg("bar", "0.0.1");
61+
62+
assert_that(cargo_process("install").arg("foo").arg("bar"),
63+
execs().with_status(0).with_stdout(&format!("\
64+
{updating} registry `[..]`
65+
{downloading} foo v0.0.1 (registry file://[..])
66+
{compiling} foo v0.0.1 (registry file://[..])
67+
{installing} {home}[..]bin[..]foo[..]
68+
{downloading} bar v0.0.1 (registry file://[..])
69+
{compiling} bar v0.0.1 (registry file://[..])
70+
{installing} {home}[..]bin[..]bar[..]
71+
",
72+
updating = UPDATING,
73+
downloading = DOWNLOADING,
74+
compiling = COMPILING,
75+
installing = INSTALLING,
76+
home = cargo_home().display())));
77+
assert_that(cargo_home(), has_installed_exe("foo"));
78+
assert_that(cargo_home(), has_installed_exe("bar"));
79+
80+
assert_that(cargo_process("uninstall").arg("foo"),
81+
execs().with_status(0).with_stdout(&format!("\
82+
{removing} {home}[..]bin[..]foo[..]
83+
",
84+
removing = REMOVING,
85+
home = cargo_home().display())));
86+
assert_that(cargo_process("uninstall").arg("bar"),
87+
execs().with_status(0).with_stdout(&format!("\
88+
{removing} {home}[..]bin[..]bar[..]
89+
",
90+
removing = REMOVING,
91+
home = cargo_home().display())));
92+
assert_that(cargo_home(), is_not(has_installed_exe("foo")));
93+
assert_that(cargo_home(), is_not(has_installed_exe("bar")));
94+
});
95+
96+
test!(pick_max_version {
5997
pkg("foo", "0.0.1");
6098
pkg("foo", "0.0.2");
6199

0 commit comments

Comments
 (0)