Skip to content

Commit

Permalink
refactor(self-update): extract get_and_parse_new_rustup_version()
Browse files Browse the repository at this point in the history
  • Loading branch information
rami3l committed Apr 21, 2024
1 parent b19d033 commit f826a2d
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/cli/self_update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1106,12 +1106,9 @@ pub(crate) fn update(cfg: &Cfg) -> Result<utils::ExitCode> {

match prepare_update()? {
Some(setup_path) => {
let version = match get_new_rustup_version(&setup_path) {
Some(new_version) => parse_new_rustup_version(new_version),
None => {
err!("failed to get rustup version");
return Ok(utils::ExitCode(1));
}
let Some(version) = get_and_parse_new_rustup_version(&setup_path) else {
err!("failed to get rustup version");
return Ok(utils::ExitCode(1));
};

let _ = common::show_channel_update(
Expand All @@ -1135,6 +1132,10 @@ pub(crate) fn update(cfg: &Cfg) -> Result<utils::ExitCode> {
Ok(utils::ExitCode(0))
}

fn get_and_parse_new_rustup_version(path: &Path) -> Option<String> {
get_new_rustup_version(path).map(parse_new_rustup_version)
}

fn get_new_rustup_version(path: &Path) -> Option<String> {
match Command::new(path).arg("--version").output() {
Err(_) => None,
Expand Down

0 comments on commit f826a2d

Please sign in to comment.