From 9f59c8e239069b3940fa31250e180ace4e5db604 Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Fri, 4 Oct 2024 12:24:18 +0100 Subject: [PATCH] Respect empty --- crates/uv-cli/src/lib.rs | 15 ++++++++++++++- crates/uv-cli/src/options.rs | 33 ++++++++++++++++++++++++--------- 2 files changed, 38 insertions(+), 10 deletions(-) diff --git a/crates/uv-cli/src/lib.rs b/crates/uv-cli/src/lib.rs index db05214082cd..56a4f0a88186 100644 --- a/crates/uv-cli/src/lib.rs +++ b/crates/uv-cli/src/lib.rs @@ -779,6 +779,18 @@ fn parse_index_url(input: &str) -> Result, String> { } } +/// Parse a string into an [`FlatIndexLocation`], mapping the empty string to `None`. +fn parse_flat_index(input: &str) -> Result, String> { + if input.is_empty() { + Ok(Maybe::None) + } else { + match FlatIndexLocation::from_str(input) { + Ok(url) => Ok(Maybe::Some(url)), + Err(err) => Err(err.to_string()), + } + } +} + /// Parse a string into an [`Url`], mapping the empty string to `None`. fn parse_insecure_host(input: &str) -> Result, String> { if input.is_empty() { @@ -3735,9 +3747,10 @@ pub struct IndexArgs { short, env = "UV_FIND_LINKS", value_delimiter = ' ', + value_parser = parse_flat_index, help_heading = "Index options" )] - pub find_links: Option>, + pub find_links: Option>>, /// Ignore the registry index (e.g., PyPI), instead relying on direct URL dependencies and those /// provided via `--find-links`. diff --git a/crates/uv-cli/src/options.rs b/crates/uv-cli/src/options.rs index fb7cd5235c58..3fe5d0e77ea4 100644 --- a/crates/uv-cli/src/options.rs +++ b/crates/uv-cli/src/options.rs @@ -194,14 +194,19 @@ impl From for PipOptions { Self { index_url: index_url.and_then(Maybe::into_option), - extra_index_url: extra_index_url.map(|extra_index_urls| { - extra_index_urls + extra_index_url: extra_index_url.map(|extra_index_url| { + extra_index_url .into_iter() .filter_map(Maybe::into_option) .collect() }), no_index: if no_index { Some(true) } else { None }, - find_links, + find_links: find_links.map(|find_links| { + find_links + .into_iter() + .filter_map(Maybe::into_option) + .collect() + }), ..PipOptions::default() } } @@ -243,8 +248,8 @@ pub fn resolver_options( ResolverOptions { index_url: index_args.index_url.and_then(Maybe::into_option), - extra_index_url: index_args.extra_index_url.map(|extra_index_urls| { - extra_index_urls + extra_index_url: index_args.extra_index_url.map(|extra_index_url| { + extra_index_url .into_iter() .filter_map(Maybe::into_option) .collect() @@ -254,7 +259,12 @@ pub fn resolver_options( } else { None }, - find_links: index_args.find_links, + find_links: index_args.find_links.map(|find_links| { + find_links + .into_iter() + .filter_map(Maybe::into_option) + .collect() + }), upgrade: flag(upgrade, no_upgrade), upgrade_package: Some(upgrade_package), index_strategy, @@ -327,8 +337,8 @@ pub fn resolver_installer_options( ResolverInstallerOptions { index_url: index_args.index_url.and_then(Maybe::into_option), - extra_index_url: index_args.extra_index_url.map(|extra_index_urls| { - extra_index_urls + extra_index_url: index_args.extra_index_url.map(|extra_index_url| { + extra_index_url .into_iter() .filter_map(Maybe::into_option) .collect() @@ -338,7 +348,12 @@ pub fn resolver_installer_options( } else { None }, - find_links: index_args.find_links, + find_links: index_args.find_links.map(|find_links| { + find_links + .into_iter() + .filter_map(Maybe::into_option) + .collect() + }), upgrade: flag(upgrade, no_upgrade), upgrade_package: if upgrade_package.is_empty() { None