Skip to content

Commit

Permalink
Merge pull request #614 from julienXX/print-new-version-after-update
Browse files Browse the repository at this point in the history
Print rustup version after update
  • Loading branch information
brson authored Aug 1, 2016
2 parents 9ff9cff + 5ea4473 commit a181b2b
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 6 deletions.
31 changes: 30 additions & 1 deletion src/rustup-cli/self_update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ use std::fs::{self, File};
use std::io::Read;
use tempdir::TempDir;
use term2;
use regex::Regex;

pub struct InstallOpts {
pub default_host_triple: String,
Expand Down Expand Up @@ -1125,13 +1126,41 @@ pub fn update() -> Result<()> {
}
let setup_path = try!(prepare_update());
if let Some(ref p) = setup_path {
info!("rustup updated successfully");
let version = match get_new_rustup_version(&p) {
Some(new_version) => parse_new_rustup_version(new_version),
None => {
err!("failed to get rustup version");
process::exit(1);
}
};

info!("rustup updated successfully to {}", version);
try!(run_update(p));
}

Ok(())
}

fn get_new_rustup_version(path: &Path) -> Option<String> {
match Command::new(path).arg("--version").output() {
Err(_) => None,
Ok(output) => match String::from_utf8(output.stdout) {
Ok(version) => Some(version),
Err(_) => None
}
}
}

fn parse_new_rustup_version(version: String) -> String {
let re = Regex::new(r"\d+.\d+.\d+[0-9a-zA-Z-]*").unwrap();
let capture = re.captures(&version);
let matched_version = match capture {
Some(cap) => cap.at(0).unwrap(),
None => "(unknown)"
};
String::from(matched_version)
}

pub fn prepare_update() -> Result<Option<PathBuf>> {
let ref cargo_home = try!(utils::cargo_home());
let ref rustup_path = cargo_home.join(&format!("bin/rustup{}", EXE_SUFFIX));
Expand Down
13 changes: 8 additions & 5 deletions tests/cli-self-upd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -456,14 +456,17 @@ fn install_doesnt_modify_path_if_passed_no_modify_path() {

#[test]
fn update_exact() {
update_setup(&|config, _| {
expect_ok(config, &["rustup-init", "-y"]);
expect_ok_ex(config, &["rustup", "self", "update"],
r"",
let version = env!("CARGO_PKG_VERSION");
let expected_output = &(
r"info: checking for self-updates
info: downloading self-update
info: rustup updated successfully
info: rustup updated successfully to ".to_owned() + version + "
");

update_setup(&|config, _| {
expect_ok(config, &["rustup-init", "-y"]);
expect_ok_ex(config, &["rustup", "self", "update"],
r"", expected_output)
});
}

Expand Down

0 comments on commit a181b2b

Please sign in to comment.