From 43c837f7bb33ce80c555edeed8b68274a000d6c7 Mon Sep 17 00:00:00 2001 From: konsti Date: Mon, 18 Dec 2023 22:50:47 +0100 Subject: [PATCH] Show enum defaults in `--help` output (#693) With `Option` and `.unwrap_or_default()` later, the default of `T` isn't shown in the help output. Old: ``` --link-mode The method to use when installing packages from the global cache Possible values: - clone: Clone (i.e., copy-on-write) packages from the wheel into the site packages - copy: Copy packages from the wheel into the site packages - hardlink: Hard link packages from the wheel into the site packages -q, --quiet Do not print any output --resolution Possible values: - highest: Resolve the highest compatible version of each package - lowest: Resolve the lowest compatible version of each package - lowest-direct: Resolve the lowest compatible version of any direct dependencies, and the highest compatible version of any transitive dependencies --prerelease Possible values: - disallow: Disallow all pre-release versions - allow: Allow all pre-release versions - if-necessary: Allow pre-release versions if all versions of a package are pre-release - explicit: Allow pre-release versions for first-party packages with explicit pre-release markers in their version requirements - if-necessary-or-explicit: Allow pre-release versions if all versions of a package are pre-release, or if the package has an explicit pre-release marker in its version requirements ``` ![Screenshot from 2023-12-18 21-04-16](https://github.com/astral-sh/puffin/assets/6826232/6b3cb47a-f224-408a-8d7a-186ebeb88ecd) New: ``` --link-mode The method to use when installing packages from the global cache [default: hardlink] Possible values: - clone: Clone (i.e., copy-on-write) packages from the wheel into the site packages - copy: Copy packages from the wheel into the site packages - hardlink: Hard link packages from the wheel into the site packages -q, --quiet Do not print any output --resolution [default: highest] Possible values: - highest: Resolve the highest compatible version of each package - lowest: Resolve the lowest compatible version of each package - lowest-direct: Resolve the lowest compatible version of any direct dependencies, and the highest compatible version of any transitive dependencies --prerelease [default: if-necessary-or-explicit] Possible values: - disallow: Disallow all pre-release versions - allow: Allow all pre-release versions - if-necessary: Allow pre-release versions if all versions of a package are pre-release - explicit: Allow pre-release versions for first-party packages with explicit pre-release markers in their version requirements - if-necessary-or-explicit: Allow pre-release versions if all versions of a package are pre-release, or if the package has an explicit pre-release marker in its version requirements ``` ![image](https://github.com/astral-sh/puffin/assets/6826232/26c2c391-d959-4769-999d-481b3f179502) --- crates/puffin-cli/src/main.rs | 36 +++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/crates/puffin-cli/src/main.rs b/crates/puffin-cli/src/main.rs index 5ab6314e9..700af7587 100644 --- a/crates/puffin-cli/src/main.rs +++ b/crates/puffin-cli/src/main.rs @@ -137,11 +137,11 @@ struct PipCompileArgs { #[clap(long, conflicts_with = "extra")] all_extras: bool, - #[clap(long, value_enum)] - resolution: Option, + #[clap(long, value_enum, default_value_t = ResolutionMode::default())] + resolution: ResolutionMode, - #[clap(long, value_enum)] - prerelease: Option, + #[clap(long, value_enum, default_value_t = PreReleaseMode::default())] + prerelease: PreReleaseMode, /// Write the compiled requirements to the given `requirements.txt` file. #[clap(short, long)] @@ -210,8 +210,8 @@ struct PipSyncArgs { reinstall_package: Vec, /// The method to use when installing packages from the global cache. - #[clap(long, value_enum)] - link_mode: Option, + #[clap(long, value_enum, default_value_t = install_wheel_rs::linker::LinkMode::default())] + link_mode: install_wheel_rs::linker::LinkMode, /// The URL of the Python Package Index. #[clap(long, short, default_value = IndexUrl::Pypi.as_str())] @@ -291,14 +291,14 @@ struct PipInstallArgs { reinstall_package: Vec, /// The method to use when installing packages from the global cache. - #[clap(long, value_enum)] - link_mode: Option, + #[clap(long, value_enum, default_value_t = install_wheel_rs::linker::LinkMode::default())] + link_mode: install_wheel_rs::linker::LinkMode, - #[clap(long, value_enum)] - resolution: Option, + #[clap(long, value_enum, default_value_t = ResolutionMode::default())] + resolution: ResolutionMode, - #[clap(long, value_enum)] - prerelease: Option, + #[clap(long, value_enum, default_value_t = PreReleaseMode::default())] + prerelease: PreReleaseMode, /// Write the compiled requirements to the given `requirements.txt` file. #[clap(short, long)] @@ -447,8 +447,8 @@ async fn inner() -> Result { &overrides, extras, args.output_file.as_deref(), - args.resolution.unwrap_or_default(), - args.prerelease.unwrap_or_default(), + args.resolution, + args.prerelease, args.upgrade.into(), index_urls, args.no_build, @@ -471,7 +471,7 @@ async fn inner() -> Result { commands::pip_sync( &sources, &reinstall, - args.link_mode.unwrap_or_default(), + args.link_mode, index_urls, args.no_build, cache, @@ -512,11 +512,11 @@ async fn inner() -> Result { &constraints, &overrides, &extras, - args.resolution.unwrap_or_default(), - args.prerelease.unwrap_or_default(), + args.resolution, + args.prerelease, index_urls, &reinstall, - args.link_mode.unwrap_or_default(), + args.link_mode, args.no_build, args.exclude_newer, cache,