uv icon indicating copy to clipboard operation
uv copied to clipboard

missing default in the `--help` output.

Open ChannyClaus opened this issue 1 year ago • 4 comments

from uv pip install --help:

      --link-mode <LINK_MODE>
          The method to use when installing packages from the global cache [env: UV_LINK_MODE=] [possible
          values: clone, copy, hardlink, symlink]

it is not immediately obvious what the default is for --link-mode. it's not prohibitively difficult to figure out the default from looking at the code but it would be even nicer to be able to not have to look at the code? https://github.com/astral-sh/uv/blob/ad8e3a2c323d97c83acf541453ac65725c7c2edc/crates/install-wheel-rs/src/linker.rs#L251-L259

there seem to be some other flags like --resolution which doesn't show the default in the --help output, while --index-url does have the default included:

  -i, --index-url <INDEX_URL>
          The URL of the Python package index (by default: <https://pypi.org/simple>) [env: UV_INDEX_URL=]
      --extra-index-url <EXTRA_INDEX_URL>

(similar issue for other commands uv pip compile --annotation-style, etc)

ChannyClaus avatar Aug 17 '24 19:08 ChannyClaus

Agree we should say what the default value is — though sometimes it differs based on runtime information. Is there a way we can get Clap to include this for us?

zanieb avatar Aug 17 '24 21:08 zanieb

seems like default_value_t (or something similar) should do the trick?

$ cat src/main.rs 
use clap::Parser;

/// Simple program to greet a person
#[derive(Parser, Debug)]
#[command(version, about, long_about = None)]
struct Args {
    /// Name of the person to greet
    #[arg(short, long)]
    name: String,

    /// Number of times to greet
    #[arg(short, long, default_value_t = 1)]
    count: u8,
}

fn main() {
    let args = Args::parse();

    for _ in 0..args.count {
        println!("Hello {}!", args.name);
    }
$ cargo run --quiet -- --help
Simple program to greet a person

Usage: clap-test [OPTIONS] --name <NAME>

Options:
  -n, --name <NAME>    Name of the person to greet
  -c, --count <COUNT>  Number of times to greet [default: 1]
  -h, --help           Print help
  -V, --version        Print version

let me see if this is easily adaptable for uv.

ChannyClaus avatar Aug 17 '24 23:08 ChannyClaus

You should be able to make it work by changing Option<LinkMode> to LinkMode and setting default_value_t to LinkMode::default().

      --link-mode <LINK_MODE>                  The method to use when installing packages from the global cache [env: UV_LINK_MODE=] [default: clone] [possible values: clone, copy, hardlink, symlink]

eth3lbert avatar Aug 18 '24 11:08 eth3lbert

Oh interesting. So we'll need to audit all of our uses of Option for CLI options? Fun. I'm willing to review these — preferably one at a time? not sure.

zanieb avatar Aug 18 '24 13:08 zanieb