Skip to content

Commit af0867b

Browse files
Xerxes-2rami3l
authored andcommitted
apply smart guess to rustup update/uninstall self
Use original error instead of rewriting avoid duplicate `.to_string()` remove unnecessary `.as_str()`
1 parent d4bbf6c commit af0867b

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/cli/rustup_mode.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use std::fmt;
33
use std::io::Write;
44
use std::path::{Path, PathBuf};
55
use std::process::ExitStatus;
6+
use std::str::FromStr;
67

78
use anyhow::{anyhow, Error, Result};
89
use clap::{builder::PossibleValue, Args, CommandFactory, Parser, Subcommand, ValueEnum};
@@ -135,7 +136,7 @@ enum RustupSubcmd {
135136
)]
136137
Update {
137138
/// Toolchain name, such as 'stable', 'nightly', or '1.8.0'. For more information see `rustup help toolchain`
138-
#[arg(num_args = 1..)]
139+
#[arg(num_args = 1.., value_parser = update_toolchain_value_parser)]
139140
toolchain: Vec<PartialToolchainDesc>,
140141

141142
/// Don't perform self update when running the `rustup update` command
@@ -258,6 +259,14 @@ enum RustupSubcmd {
258259
},
259260
}
260261

262+
fn update_toolchain_value_parser(s: &str) -> Result<PartialToolchainDesc> {
263+
PartialToolchainDesc::from_str(s).inspect_err(|_| {
264+
if s == "self" {
265+
info!("if you meant to update rustup itself, use `rustup self update`");
266+
}
267+
})
268+
}
269+
261270
#[derive(Debug, Subcommand)]
262271
enum ShowSubcmd {
263272
/// Show the active toolchain

src/toolchain.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,13 @@ impl<'a> Toolchain<'a> {
457457
fs::remove_dir_all(&path)?;
458458
true
459459
} else {
460+
let name = name.to_string();
460461
info!("no toolchain installed for '{name}'");
462+
if name == "self" {
463+
info!(
464+
"if you meant to uninstall rustup itself, use `rustup self uninstall`"
465+
);
466+
}
461467
false
462468
}
463469
}

0 commit comments

Comments
 (0)