Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --force option to uv toolchain install #4313

Merged
merged 1 commit into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion crates/uv/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
27 changes: 16 additions & 11 deletions crates/uv/src/commands/toolchain/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions crates/uv/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -740,6 +740,7 @@ async fn run() -> Result<ExitStatus> {

commands::toolchain_install(
args.target,
args.force,
globals.native_tls,
globals.connectivity,
globals.preview,
Expand Down
5 changes: 3 additions & 2 deletions crates/uv/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
}
}

Expand Down
Loading