Skip to content

Commit fb1bd76

Browse files
committed
cli: add rustup self uninstall --no-modify-path
1 parent f8dab60 commit fb1bd76

File tree

2 files changed

+36
-7
lines changed

2 files changed

+36
-7
lines changed

src/cli/rustup_mode.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -532,8 +532,13 @@ enum SelfSubcmd {
532532

533533
/// Uninstall rustup
534534
Uninstall {
535+
/// Continue without confirmation
535536
#[arg(short = 'y')]
536537
no_prompt: bool,
538+
539+
/// Do not clean up the `PATH` environment variable
540+
#[arg(long)]
541+
no_modify_path: bool,
537542
},
538543

539544
/// Upgrade the internal data format
@@ -726,7 +731,10 @@ pub async fn main(
726731
RustupSubcmd::Man { command, toolchain } => man(cfg, &command, toolchain).await,
727732
RustupSubcmd::Self_ { subcmd } => match subcmd {
728733
SelfSubcmd::Update => self_update::update(cfg).await,
729-
SelfSubcmd::Uninstall { no_prompt } => self_update::uninstall(no_prompt, process),
734+
SelfSubcmd::Uninstall {
735+
no_prompt,
736+
no_modify_path,
737+
} => self_update::uninstall(no_prompt, no_modify_path, process),
730738
SelfSubcmd::UpgradeData => cfg.upgrade_data().map(|_| ExitCode(0)),
731739
},
732740
RustupSubcmd::Set { subcmd } => match subcmd {

src/cli/self_update.rs

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,17 @@ This will uninstall all Rust toolchains and data, and remove
474474
};
475475
}
476476

477+
macro_rules! pre_uninstall_msg_no_modify_path {
478+
() => {
479+
r"# Thanks for hacking in Rust!
480+
481+
This will uninstall all Rust toolchains and data.
482+
Your `PATH` environment variable will not be touched.
483+
484+
"
485+
};
486+
}
487+
477488
static DEFAULT_UPDATE_ROOT: &str = "https://static.rust-lang.org/rustup";
478489

479490
fn update_root(process: &Process) -> String {
@@ -968,7 +979,11 @@ async fn maybe_install_rust(opts: InstallOpts<'_>, cfg: &mut Cfg<'_>) -> Result<
968979
Ok(())
969980
}
970981

971-
pub(crate) fn uninstall(no_prompt: bool, process: &Process) -> Result<utils::ExitCode> {
982+
pub(crate) fn uninstall(
983+
no_prompt: bool,
984+
no_modify_path: bool,
985+
process: &Process,
986+
) -> Result<utils::ExitCode> {
972987
if cfg!(feature = "no-self-update") {
973988
error!("self-uninstall is disabled for this build of rustup");
974989
error!("you should probably use your system package manager to uninstall rustup");
@@ -983,10 +998,14 @@ pub(crate) fn uninstall(no_prompt: bool, process: &Process) -> Result<utils::Exi
983998

984999
if !no_prompt {
9851000
writeln!(process.stdout().lock())?;
986-
let msg = format!(
987-
pre_uninstall_msg!(),
988-
cargo_home = canonical_cargo_home(process)?
989-
);
1001+
let msg = if no_modify_path {
1002+
format!(pre_uninstall_msg_no_modify_path!())
1003+
} else {
1004+
format!(
1005+
pre_uninstall_msg!(),
1006+
cargo_home = canonical_cargo_home(process)?
1007+
)
1008+
};
9901009
md(&mut process.stdout(), msg);
9911010
if !common::confirm("\nContinue? (y/N)", false, process)? {
9921011
info!("aborting uninstallation");
@@ -1005,7 +1024,9 @@ pub(crate) fn uninstall(no_prompt: bool, process: &Process) -> Result<utils::Exi
10051024
info!("removing cargo home");
10061025

10071026
// Remove CARGO_HOME/bin from PATH
1008-
do_remove_from_path(process)?;
1027+
if !no_modify_path {
1028+
do_remove_from_path(process)?;
1029+
}
10091030

10101031
// Delete everything in CARGO_HOME *except* the rustup bin
10111032

0 commit comments

Comments
 (0)