Add --force option to uv toolchain install (#4313)

This commit is contained in:
Zanie Blue 2024-06-13 17:43:40 -04:00 committed by GitHub
parent 92802df223
commit b74de31967
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 25 additions and 14 deletions

View file

@ -2081,8 +2081,12 @@ pub(crate) struct ToolchainListArgs {
pub(crate) struct ToolchainInstallArgs {
/// The toolchain to install.
///
/// If not provided, the latest available version will be installed.
/// If not provided, the latest available version will be installed unless a toolchain was previously installed.
pub(crate) target: Option<String>,
/// Force the installation of the toolchain, even if it is already installed.
#[arg(long, short)]
pub(crate) force: bool,
}
#[derive(Args)]

View file

@ -16,6 +16,7 @@ use crate::printer::Printer;
#[allow(clippy::too_many_arguments)]
pub(crate) async fn install(
target: Option<String>,
force: bool,
native_tls: bool,
connectivity: Connectivity,
preview: PreviewMode,
@ -58,19 +59,23 @@ pub(crate) async fn install(
toolchain.key()
)?;
if matches!(request, ToolchainRequest::Any) {
writeln!(
printer.stderr(),
"A toolchain is already installed. Use `uv toolchain install <request>` to install a specific toolchain.",
)?;
if force {
writeln!(printer.stderr(), "Forcing reinstallation...")?;
} else {
writeln!(
printer.stderr(),
"Already installed at {}",
toolchain.path().user_display()
)?;
if matches!(request, ToolchainRequest::Any) {
writeln!(
printer.stderr(),
"A toolchain is already installed. Use `uv toolchain install <request>` to install a specific toolchain.",
)?;
} else {
writeln!(
printer.stderr(),
"Already installed at {}",
toolchain.path().user_display()
)?;
}
return Ok(ExitStatus::Success);
}
return Ok(ExitStatus::Success);
}
// Fill platform information missing from the request

View file

@ -740,6 +740,7 @@ async fn run() -> Result<ExitStatus> {
commands::toolchain_install(
args.target,
args.force,
globals.native_tls,
globals.connectivity,
globals.preview,

View file

@ -249,15 +249,16 @@ impl ToolchainListSettings {
#[derive(Debug, Clone)]
pub(crate) struct ToolchainInstallSettings {
pub(crate) target: Option<String>,
pub(crate) force: bool,
}
impl ToolchainInstallSettings {
/// Resolve the [`ToolchainInstallSettings`] from the CLI and workspace configuration.
#[allow(clippy::needless_pass_by_value)]
pub(crate) fn resolve(args: ToolchainInstallArgs, _workspace: Option<Workspace>) -> Self {
let ToolchainInstallArgs { target } = args;
let ToolchainInstallArgs { target, force } = args;
Self { target }
Self { target, force }
}
}