From 463c61dd2727d0a9ca97dc7a2b0a25cd232388d6 Mon Sep 17 00:00:00 2001 From: David Soria Parra Date: Fri, 16 Feb 2024 13:27:57 +0000 Subject: [PATCH] add --modify-path and --no-modify-path to rye self install This adds the option to never modify paths to rye install, even when `--yes` is provided. This addresses #620. We offer a --modify-path and a --no-modify-path option to either always modify or never modify. Providing --yes, will be the same as --modify-path. This is in line with other command line tools like curl, git and ripgrep. We do this by adding a new enum YesNoArg, which can be obtained by providing an ArgGroup with respective modify_path and no_modify_path boolean values. --- rye/src/cli/rye.rs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/rye/src/cli/rye.rs b/rye/src/cli/rye.rs index 5ab3972344..9006832428 100644 --- a/rye/src/cli/rye.rs +++ b/rye/src/cli/rye.rs @@ -96,6 +96,9 @@ pub struct InstallCommand { /// Use a specific toolchain version. #[arg(long)] toolchain_version: Option, + /// Skip modifying the PATH environment variable. + #[arg(long, default_value = "false")] + skip_modify_path: bool, } #[derive(Debug, Copy, Clone)] @@ -263,6 +266,7 @@ fn install(args: InstallCommand) -> Result<(), Error> { }, args.toolchain.as_deref(), args.toolchain_version, + args.skip_modify_path, ) } @@ -351,6 +355,7 @@ fn perform_install( mode: InstallMode, toolchain_path: Option<&Path>, toolchain_version: Option, + skip_modify_path: bool, ) -> Result<(), Error> { let mut config = Config::current(); let mut registered_toolchain: Option = None; @@ -547,7 +552,14 @@ fn perform_install( prompt_for_default_toolchain(registered_toolchain.unwrap(), config_doc)?; } - add_rye_to_path(&mode, shims.as_path())?; + if skip_modify_path { + echo!( + "Skipping PATH modification. You will need to add {} to your PATH manually.", + style(shims.display()).cyan() + ); + } else { + add_rye_to_path(&mode, shims.as_path())?; + } echo!(); echo!("{}", style("All done!").green()); @@ -670,7 +682,7 @@ pub fn auto_self_install() -> Result { crate::request_continue_prompt(); } - perform_install(InstallMode::AutoInstall, None, None)?; + perform_install(InstallMode::AutoInstall, None, None, false)?; Ok(true) } }