Show enum defaults in --help output (#693)

With `Option<T>` and `.unwrap_or_default()` later, the default of `T`
isn't shown in the help output.

Old:

```
      --link-mode <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 <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 <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](6b3cb47a-f224-408a-8d7a-186ebeb88ecd)

New:

```
      --link-mode <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 <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 <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](26c2c391-d959-4769-999d-481b3f179502)
This commit is contained in:
konsti 2023-12-18 22:50:47 +01:00 committed by GitHub
parent 98fcb76015
commit 43c837f7bb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -137,11 +137,11 @@ struct PipCompileArgs {
#[clap(long, conflicts_with = "extra")] #[clap(long, conflicts_with = "extra")]
all_extras: bool, all_extras: bool,
#[clap(long, value_enum)] #[clap(long, value_enum, default_value_t = ResolutionMode::default())]
resolution: Option<ResolutionMode>, resolution: ResolutionMode,
#[clap(long, value_enum)] #[clap(long, value_enum, default_value_t = PreReleaseMode::default())]
prerelease: Option<PreReleaseMode>, prerelease: PreReleaseMode,
/// Write the compiled requirements to the given `requirements.txt` file. /// Write the compiled requirements to the given `requirements.txt` file.
#[clap(short, long)] #[clap(short, long)]
@ -210,8 +210,8 @@ struct PipSyncArgs {
reinstall_package: Vec<PackageName>, reinstall_package: Vec<PackageName>,
/// The method to use when installing packages from the global cache. /// The method to use when installing packages from the global cache.
#[clap(long, value_enum)] #[clap(long, value_enum, default_value_t = install_wheel_rs::linker::LinkMode::default())]
link_mode: Option<install_wheel_rs::linker::LinkMode>, link_mode: install_wheel_rs::linker::LinkMode,
/// The URL of the Python Package Index. /// The URL of the Python Package Index.
#[clap(long, short, default_value = IndexUrl::Pypi.as_str())] #[clap(long, short, default_value = IndexUrl::Pypi.as_str())]
@ -291,14 +291,14 @@ struct PipInstallArgs {
reinstall_package: Vec<PackageName>, reinstall_package: Vec<PackageName>,
/// The method to use when installing packages from the global cache. /// The method to use when installing packages from the global cache.
#[clap(long, value_enum)] #[clap(long, value_enum, default_value_t = install_wheel_rs::linker::LinkMode::default())]
link_mode: Option<install_wheel_rs::linker::LinkMode>, link_mode: install_wheel_rs::linker::LinkMode,
#[clap(long, value_enum)] #[clap(long, value_enum, default_value_t = ResolutionMode::default())]
resolution: Option<ResolutionMode>, resolution: ResolutionMode,
#[clap(long, value_enum)] #[clap(long, value_enum, default_value_t = PreReleaseMode::default())]
prerelease: Option<PreReleaseMode>, prerelease: PreReleaseMode,
/// Write the compiled requirements to the given `requirements.txt` file. /// Write the compiled requirements to the given `requirements.txt` file.
#[clap(short, long)] #[clap(short, long)]
@ -447,8 +447,8 @@ async fn inner() -> Result<ExitStatus> {
&overrides, &overrides,
extras, extras,
args.output_file.as_deref(), args.output_file.as_deref(),
args.resolution.unwrap_or_default(), args.resolution,
args.prerelease.unwrap_or_default(), args.prerelease,
args.upgrade.into(), args.upgrade.into(),
index_urls, index_urls,
args.no_build, args.no_build,
@ -471,7 +471,7 @@ async fn inner() -> Result<ExitStatus> {
commands::pip_sync( commands::pip_sync(
&sources, &sources,
&reinstall, &reinstall,
args.link_mode.unwrap_or_default(), args.link_mode,
index_urls, index_urls,
args.no_build, args.no_build,
cache, cache,
@ -512,11 +512,11 @@ async fn inner() -> Result<ExitStatus> {
&constraints, &constraints,
&overrides, &overrides,
&extras, &extras,
args.resolution.unwrap_or_default(), args.resolution,
args.prerelease.unwrap_or_default(), args.prerelease,
index_urls, index_urls,
&reinstall, &reinstall,
args.link_mode.unwrap_or_default(), args.link_mode,
args.no_build, args.no_build,
args.exclude_newer, args.exclude_newer,
cache, cache,