diff --git a/rustup-init.sh b/rustup-init.sh index 753f93ea9bd..1bee0462d2a 100755 --- a/rustup-init.sh +++ b/rustup-init.sh @@ -20,6 +20,7 @@ USAGE: FLAGS: -v, --verbose Enable verbose output + -q, --quiet Disable progress output -y Disable confirmation prompt. --no-modify-path Don't configure the PATH environment variable -h, --help Prints help information diff --git a/src/cli/common.rs b/src/cli/common.rs index e56a5fb5c51..67650e71939 100644 --- a/src/cli/common.rs +++ b/src/cli/common.rs @@ -104,11 +104,11 @@ pub fn read_line() -> Result { .ok_or_else(|| "unable to read from stdin for confirmation".into()) } -pub fn set_globals(verbose: bool) -> Result { +pub fn set_globals(verbose: bool, quiet: bool) -> Result { use crate::download_tracker::DownloadTracker; use std::cell::RefCell; - let download_tracker = RefCell::new(DownloadTracker::new()); + let download_tracker = RefCell::new(DownloadTracker::new().with_display_progress(!quiet)); Ok(Cfg::from_env(Arc::new(move |n: Notification<'_>| { if download_tracker.borrow_mut().handle_notification(&n) { diff --git a/src/cli/download_tracker.rs b/src/cli/download_tracker.rs index 57e3250506b..7ee6d063976 100644 --- a/src/cli/download_tracker.rs +++ b/src/cli/download_tracker.rs @@ -44,6 +44,8 @@ pub struct DownloadTracker { displayed_charcount: Option, /// What units to show progress in units: Vec, + /// Whether we display progress + display_progress: bool, } impl DownloadTracker { @@ -59,9 +61,15 @@ impl DownloadTracker { term: term2::stdout(), displayed_charcount: None, units: vec!["B".into(); 1], + display_progress: true, } } + pub fn with_display_progress(mut self, display_progress: bool) -> DownloadTracker { + self.display_progress = display_progress; + self + } + pub fn handle_notification(&mut self, n: &Notification<'_>) -> bool { match *n { Notification::Install(In::Utils(Un::DownloadContentLengthReceived(content_len))) => { @@ -109,7 +117,9 @@ impl DownloadTracker { Some(prev) => { let elapsed = current_time - prev; if elapsed >= 1.0 { - self.display(); + if self.display_progress { + self.display(); + } self.last_sec = Some(current_time); if self.downloaded_last_few_secs.len() == DOWNLOAD_TRACK_COUNT { self.downloaded_last_few_secs.pop_back(); diff --git a/src/cli/proxy_mode.rs b/src/cli/proxy_mode.rs index adadb60bbc7..c2031abce1a 100644 --- a/src/cli/proxy_mode.rs +++ b/src/cli/proxy_mode.rs @@ -39,7 +39,7 @@ pub fn main() -> Result<()> { env::args_os().skip(2).collect() }; - let cfg = set_globals(false)?; + let cfg = set_globals(false, true)?; cfg.check_metadata_version()?; direct_proxy(&cfg, &arg0, toolchain, &cmd_args)? }; diff --git a/src/cli/rustup_mode.rs b/src/cli/rustup_mode.rs index 629bddda4f3..ef606eb08c2 100644 --- a/src/cli/rustup_mode.rs +++ b/src/cli/rustup_mode.rs @@ -31,7 +31,8 @@ pub fn main() -> Result<()> { let matches = cli().get_matches(); let verbose = matches.is_present("verbose"); - let cfg = &common::set_globals(verbose)?; + let quiet = matches.is_present("quiet"); + let cfg = &common::set_globals(verbose, quiet)?; if maybe_upgrade_data(cfg, &matches)? { return Ok(()); @@ -118,6 +119,12 @@ pub fn cli() -> App<'static, 'static> { .short("v") .long("verbose"), ) + .arg( + Arg::with_name("quiet") + .help("Disable progress output") + .short("q") + .long("quiet"), + ) .subcommand( SubCommand::with_name("dump-testament") .about("Dump information about the build") diff --git a/src/cli/self_update.rs b/src/cli/self_update.rs index 2b8968ac50f..1cde8df812a 100644 --- a/src/cli/self_update.rs +++ b/src/cli/self_update.rs @@ -231,7 +231,7 @@ fn canonical_cargo_home() -> Result { /// Installing is a simple matter of copying the running binary to /// `CARGO_HOME`/bin, hard-linking the various Rust tools to it, /// and adding `CARGO_HOME`/bin to PATH. -pub fn install(no_prompt: bool, verbose: bool, mut opts: InstallOpts) -> Result<()> { +pub fn install(no_prompt: bool, verbose: bool, quiet: bool, mut opts: InstallOpts) -> Result<()> { do_pre_install_sanity_checks()?; do_pre_install_options_sanity_checks(&opts)?; check_existence_of_rustc_or_cargo_in_path(no_prompt)?; @@ -278,7 +278,12 @@ pub fn install(no_prompt: bool, verbose: bool, mut opts: InstallOpts) -> Result< do_add_to_path(&get_add_path_methods())?; } utils::create_rustup_home()?; - maybe_install_rust(&opts.default_toolchain, &opts.default_host_triple, verbose)?; + maybe_install_rust( + &opts.default_toolchain, + &opts.default_host_triple, + verbose, + quiet, + )?; if cfg!(unix) { let env_file = utils::cargo_home()?.join("env"); @@ -715,8 +720,13 @@ pub fn install_proxies() -> Result<()> { Ok(()) } -fn maybe_install_rust(toolchain_str: &str, default_host_triple: &str, verbose: bool) -> Result<()> { - let cfg = common::set_globals(verbose)?; +fn maybe_install_rust( + toolchain_str: &str, + default_host_triple: &str, + verbose: bool, + quiet: bool, +) -> Result<()> { + let cfg = common::set_globals(verbose, quiet)?; // If there is already an install, then `toolchain_str` may not be // a toolchain the user actually wants. Don't do anything. FIXME: diff --git a/src/cli/setup_mode.rs b/src/cli/setup_mode.rs index 6a5437d2f1c..6fe955d6bca 100644 --- a/src/cli/setup_mode.rs +++ b/src/cli/setup_mode.rs @@ -31,6 +31,12 @@ pub fn main() -> Result<()> { .long("verbose") .help("Enable verbose output"), ) + .arg( + Arg::with_name("quiet") + .short("q") + .long("quiet") + .help("Disable progress output"), + ) .arg( Arg::with_name("no-prompt") .short("y") @@ -57,6 +63,7 @@ pub fn main() -> Result<()> { let matches = cli.get_matches(); let no_prompt = matches.is_present("no-prompt"); let verbose = matches.is_present("verbose"); + let quiet = matches.is_present("quiet"); let default_host = matches .value_of("default-host") .map(std::borrow::ToOwned::to_owned) @@ -70,7 +77,7 @@ pub fn main() -> Result<()> { no_modify_path, }; - self_update::install(no_prompt, verbose, opts)?; + self_update::install(no_prompt, verbose, quiet, opts)?; Ok(()) } diff --git a/tests/cli-rustup.rs b/tests/cli-rustup.rs index 674b4ea0969..611955b75f2 100644 --- a/tests/cli-rustup.rs +++ b/tests/cli-rustup.rs @@ -65,6 +65,45 @@ info: installing component 'rust-docs' }); } +#[test] +fn rustup_stable_quiet() { + setup(&|config| { + set_current_dist_date(config, "2015-01-01"); + expect_ok( + config, + &["rustup", "--quiet", "update", "stable", "--no-self-update"], + ); + set_current_dist_date(config, "2015-01-02"); + expect_ok_ex( + config, + &["rustup", "--quiet", "update", "--no-self-update"], + for_host!( + r" + stable-{0} updated - 1.1.0 (hash-s-2) + +" + ), + for_host!( + r"info: syncing channel updates for 'stable-{0}' +info: latest update on 2015-01-02, rust version 1.1.0 +info: downloading component 'rust-std' +info: downloading component 'rustc' +info: downloading component 'cargo' +info: downloading component 'rust-docs' +info: removing previous version of component 'rust-std' +info: removing previous version of component 'rustc' +info: removing previous version of component 'cargo' +info: removing previous version of component 'rust-docs' +info: installing component 'rust-std' +info: installing component 'rustc' +info: installing component 'cargo' +info: installing component 'rust-docs' +" + ), + ); + }); +} + #[test] fn rustup_stable_no_change() { setup(&|config| { @@ -1067,6 +1106,28 @@ fn toolchain_install_is_like_update() { }); } +#[test] +fn toolchain_install_is_like_update_quiet() { + setup(&|config| { + expect_ok( + config, + &[ + "rustup", + "--quiet", + "toolchain", + "install", + "nightly", + "--no-self-update", + ], + ); + expect_stdout_ok( + config, + &["rustup", "--quiet", "run", "nightly", "rustc", "--version"], + "hash-n-2", + ); + }); +} + #[test] fn toolchain_install_is_like_update_except_that_bare_install_is_an_error() { setup(&|config| {