Skip to content

Commit 75d30f9

Browse files
committed
Display helpful advices even with -y.
Currently -y disables any helpful advices, but example usages of curl-based rustup installation frequently include -y (unfortunately). Since -y is not a silent flag but a yes-to-all flag, we can always display advices instead and (on Windows) only pause unless -y is given.
1 parent ab75525 commit 75d30f9

File tree

3 files changed

+35
-26
lines changed

3 files changed

+35
-26
lines changed

src/rustup-cli/self_update.rs

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -297,28 +297,27 @@ pub fn install(no_prompt: bool, verbose: bool,
297297
process::exit(1);
298298
}
299299

300-
// More helpful advice, skip if -y
301-
if !no_prompt {
302-
let cargo_home = try!(canonical_cargo_home());
303-
let msg = if !opts.no_modify_path {
304-
if cfg!(unix) {
305-
format!(post_install_msg_unix!(),
306-
cargo_home = cargo_home)
307-
} else {
308-
format!(post_install_msg_win!(),
309-
cargo_home = cargo_home)
310-
}
300+
let cargo_home = try!(canonical_cargo_home());
301+
let msg = if !opts.no_modify_path {
302+
if cfg!(unix) {
303+
format!(post_install_msg_unix!(),
304+
cargo_home = cargo_home)
311305
} else {
312-
if cfg!(unix) {
313-
format!(post_install_msg_unix_no_modify_path!(),
314-
cargo_home = cargo_home)
315-
} else {
316-
format!(post_install_msg_win_no_modify_path!(),
317-
cargo_home = cargo_home)
318-
}
319-
};
320-
term2::stdout().md(msg);
306+
format!(post_install_msg_win!(),
307+
cargo_home = cargo_home)
308+
}
309+
} else {
310+
if cfg!(unix) {
311+
format!(post_install_msg_unix_no_modify_path!(),
312+
cargo_home = cargo_home)
313+
} else {
314+
format!(post_install_msg_win_no_modify_path!(),
315+
cargo_home = cargo_home)
316+
}
317+
};
318+
term2::stdout().md(msg);
321319

320+
if !no_prompt {
322321
// On windows, where installation happens in a console
323322
// that may have opened just for this purpose, require
324323
// the user to press a key to continue.

src/rustup-mock/src/clitools.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,18 @@ pub fn expect_err_ex(config: &Config, args: &[&str],
234234
}
235235
}
236236

237+
pub fn expect_ok_contains(config: &Config, args: &[&str],
238+
stdout: &str, stderr: &str) {
239+
let out = run(config, args[0], &args[1..], &[]);
240+
if !out.ok || !out.stdout.contains(stdout) || !out.stderr.contains(stderr) {
241+
print_command(args, &out);
242+
println!("expected.ok: {}", true);
243+
print_indented("expected.stdout.contains", stdout);
244+
print_indented("expected.stderr.contains", stderr);
245+
panic!();
246+
}
247+
}
248+
237249
pub fn expect_timeout_ok(config: &Config, timeout: Duration, args: &[&str]) {
238250
let mut child = cmd(config, args[0], &args[1..])
239251
.stdout(Stdio::null())

tests/cli-self-upd.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,15 @@ use std::process::Command;
2727
use remove_dir_all::remove_dir_all;
2828
use rustup_mock::clitools::{self, Config, Scenario,
2929
expect_ok, expect_ok_ex,
30+
expect_ok_contains,
31+
expect_stderr_ok,
3032
expect_stdout_ok,
3133
expect_err, expect_err_ex,
3234
this_host_triple};
3335
use rustup_mock::dist::{calc_hash};
3436
use rustup_mock::{get_path, restore_path};
3537
use rustup_utils::{utils, raw};
3638

37-
#[cfg(windows)]
38-
use rustup_mock::clitools::expect_stderr_ok;
3939

4040
macro_rules! for_host { ($s: expr) => (&format!($s, this_host_triple())) }
4141

@@ -777,7 +777,7 @@ fn as_rustup_setup() {
777777
#[test]
778778
fn first_install_exact() {
779779
setup(&|config| {
780-
expect_ok_ex(config, &["rustup-init", "-y"],
780+
expect_ok_contains(config, &["rustup-init", "-y"],
781781
r"
782782
stable installed - 1.1.0 (hash-s-2)
783783
@@ -802,9 +802,7 @@ info: default toolchain set to 'stable'
802802
fn reinstall_exact() {
803803
setup(&|config| {
804804
expect_ok(config, &["rustup-init", "-y"]);
805-
expect_ok_ex(config, &["rustup-init", "-y"],
806-
r"
807-
",
805+
expect_stderr_ok(config, &["rustup-init", "-y"],
808806
r"info: updating existing rustup installation
809807
"
810808
);

0 commit comments

Comments
 (0)