From 33c65da5ca224a0f35ae3b940d3dedfd7b1da01b Mon Sep 17 00:00:00 2001 From: Zanie Blue Date: Mon, 8 Jul 2024 13:48:30 -0500 Subject: [PATCH] Display short help menu when `--help` is used --- crates/uv-cli/src/lib.rs | 5 + crates/uv/tests/help.rs | 262 ++++++------------------------- crates/uv/tests/pip_compile.rs | 10 -- crates/uv/tests/pip_install.rs | 2 +- crates/uv/tests/pip_uninstall.rs | 2 - 5 files changed, 53 insertions(+), 228 deletions(-) diff --git a/crates/uv-cli/src/lib.rs b/crates/uv-cli/src/lib.rs index 72fb381795b4..2ad27927e30b 100644 --- a/crates/uv-cli/src/lib.rs +++ b/crates/uv-cli/src/lib.rs @@ -52,6 +52,7 @@ fn extra_name_with_clap_error(arg: &str) -> Result { #[command(name = "uv", author, version = uv_version::version(), long_version = crate::version::version())] #[command(about = "An extremely fast Python package manager.")] #[command(propagate_version = true)] +#[command(disable_help_flag = true)] #[allow(clippy::struct_excessive_bools)] pub struct Cli { #[command(subcommand)] @@ -66,6 +67,10 @@ pub struct Cli { /// The path to a `uv.toml` file to use for configuration. #[arg(global = true, long, env = "UV_CONFIG_FILE")] pub config_file: Option, + + /// Print help. + #[arg(global = true, short, long, action = clap::ArgAction::HelpShort)] + help: Option, } #[derive(Parser, Debug, Clone)] diff --git a/crates/uv/tests/help.rs b/crates/uv/tests/help.rs index 7edc0ce2c271..6852d01e7842 100644 --- a/crates/uv/tests/help.rs +++ b/crates/uv/tests/help.rs @@ -102,7 +102,7 @@ fn help() { [env: UV_CONFIG_FILE=] -h, --help - Print help (see a summary with '-h') + Print help -V, --version Print version @@ -134,83 +134,29 @@ fn help_flag() { Options: -q, --quiet Do not print any output - -v, --verbose... - Use verbose output. - - You can configure fine-grained logging using the `RUST_LOG` environment variable. - () - + Use verbose output --color - Control colors in output - - [default: auto] - - Possible values: - - auto: Enables colored output only when the output is going to a terminal or TTY with - support - - always: Enables colored output regardless of the detected environment - - never: Disables colored output - + Control colors in output [default: auto] [possible values: auto, always, never] --native-tls - Whether to load TLS certificates from the platform's native certificate store. - - By default, `uv` loads certificates from the bundled `webpki-roots` crate. The - `webpki-roots` are a reliable set of trust roots from Mozilla, and including them in `uv` - improves portability and performance (especially on macOS). - - However, in some cases, you may want to use the platform's native certificate store, - especially if you're relying on a corporate trust root (e.g., for a mandatory proxy) - that's included in your system's certificate store. - - [env: UV_NATIVE_TLS=] - + Whether to load TLS certificates from the platform's native certificate store [env: + UV_NATIVE_TLS=] --offline Disable network access, relying only on locally cached data and locally available files - --python-preference - Whether to prefer using Python from uv or on the system - - Possible values: - - only-managed: Only use managed Python installations; never use system Python - installations - - installed: Prefer installed Python installations, only download managed Python - installations if no system Python installation is found - - managed: Prefer managed Python installations over system Python installations, even - if fetching is required - - system: Prefer system Python installations over managed Python installations - - only-system: Only use system Python installations; never use managed Python - installations - + Whether to prefer using Python from uv or on the system [possible values: only-managed, + installed, managed, system, only-system] --python-fetch - Whether to automatically download Python when required - - Possible values: - - automatic: Automatically fetch managed Python installations when needed - - manual: Do not automatically fetch managed Python installations; require explicit - installation - + Whether to automatically download Python when required [possible values: automatic, + manual] -n, --no-cache - Avoid reading from or writing to the cache - - [env: UV_NO_CACHE=] - + Avoid reading from or writing to the cache [env: UV_NO_CACHE=] --cache-dir [CACHE_DIR] - Path to the cache directory. - - Defaults to `$HOME/Library/Caches/uv` on macOS, `$XDG_CACHE_HOME/uv` or `$HOME/.cache/uv` - on Linux, and `{FOLDERID_LocalAppData}/uv/cache` on Windows. - - [env: UV_CACHE_DIR=] - + Path to the cache directory [env: UV_CACHE_DIR=] --config-file - The path to a `uv.toml` file to use for configuration - - [env: UV_CONFIG_FILE=] - + The path to a `uv.toml` file to use for configuration [env: UV_CONFIG_FILE=] -h, --help - Print help (see a summary with '-h') - + Print help -V, --version Print version @@ -263,7 +209,7 @@ fn help_short_flag() { --config-file The path to a `uv.toml` file to use for configuration [env: UV_CONFIG_FILE=] -h, --help - Print help (see more with '--help') + Print help -V, --version Print version @@ -369,7 +315,7 @@ fn help_subcommand() { [env: UV_CONFIG_FILE=] -h, --help - Print help (see a summary with '-h') + Print help -V, --version Print version @@ -479,7 +425,7 @@ fn help_subsubcommand() { [env: UV_CONFIG_FILE=] -h, --help - Print help (see a summary with '-h') + Print help -V, --version Print version @@ -511,83 +457,29 @@ fn help_flag_subcommand() { Options: -q, --quiet Do not print any output - -v, --verbose... - Use verbose output. - - You can configure fine-grained logging using the `RUST_LOG` environment variable. - () - + Use verbose output --color - Control colors in output - - [default: auto] - - Possible values: - - auto: Enables colored output only when the output is going to a terminal or TTY with - support - - always: Enables colored output regardless of the detected environment - - never: Disables colored output - + Control colors in output [default: auto] [possible values: auto, always, never] --native-tls - Whether to load TLS certificates from the platform's native certificate store. - - By default, `uv` loads certificates from the bundled `webpki-roots` crate. The - `webpki-roots` are a reliable set of trust roots from Mozilla, and including them in `uv` - improves portability and performance (especially on macOS). - - However, in some cases, you may want to use the platform's native certificate store, - especially if you're relying on a corporate trust root (e.g., for a mandatory proxy) - that's included in your system's certificate store. - - [env: UV_NATIVE_TLS=] - + Whether to load TLS certificates from the platform's native certificate store [env: + UV_NATIVE_TLS=] --offline Disable network access, relying only on locally cached data and locally available files - --python-preference - Whether to prefer using Python from uv or on the system - - Possible values: - - only-managed: Only use managed Python installations; never use system Python - installations - - installed: Prefer installed Python installations, only download managed Python - installations if no system Python installation is found - - managed: Prefer managed Python installations over system Python installations, even - if fetching is required - - system: Prefer system Python installations over managed Python installations - - only-system: Only use system Python installations; never use managed Python - installations - + Whether to prefer using Python from uv or on the system [possible values: only-managed, + installed, managed, system, only-system] --python-fetch - Whether to automatically download Python when required - - Possible values: - - automatic: Automatically fetch managed Python installations when needed - - manual: Do not automatically fetch managed Python installations; require explicit - installation - + Whether to automatically download Python when required [possible values: automatic, + manual] -n, --no-cache - Avoid reading from or writing to the cache - - [env: UV_NO_CACHE=] - + Avoid reading from or writing to the cache [env: UV_NO_CACHE=] --cache-dir [CACHE_DIR] - Path to the cache directory. - - Defaults to `$HOME/Library/Caches/uv` on macOS, `$XDG_CACHE_HOME/uv` or `$HOME/.cache/uv` - on Linux, and `{FOLDERID_LocalAppData}/uv/cache` on Windows. - - [env: UV_CACHE_DIR=] - + Path to the cache directory [env: UV_CACHE_DIR=] --config-file - The path to a `uv.toml` file to use for configuration - - [env: UV_CONFIG_FILE=] - + The path to a `uv.toml` file to use for configuration [env: UV_CONFIG_FILE=] -h, --help - Print help (see a summary with '-h') - + Print help -V, --version Print version @@ -608,96 +500,36 @@ fn help_flag_subsubcommand() { Usage: uv python install [OPTIONS] [TARGETS]... Arguments: - [TARGETS]... - The Python version(s) to install. - - If not provided, the requested Python version(s) will be read from the `.python-versions` - or `.python-version` files. If neither file is present, uv will check if it has installed - any Python versions. If not, it will install the latest stable version of Python. + [TARGETS]... The Python version(s) to install Options: -f, --force Force the installation of the requested Python, even if it is already installed - -q, --quiet Do not print any output - -v, --verbose... - Use verbose output. - - You can configure fine-grained logging using the `RUST_LOG` environment variable. - () - + Use verbose output --color - Control colors in output - - [default: auto] - - Possible values: - - auto: Enables colored output only when the output is going to a terminal or TTY with - support - - always: Enables colored output regardless of the detected environment - - never: Disables colored output - + Control colors in output [default: auto] [possible values: auto, always, never] --native-tls - Whether to load TLS certificates from the platform's native certificate store. - - By default, `uv` loads certificates from the bundled `webpki-roots` crate. The - `webpki-roots` are a reliable set of trust roots from Mozilla, and including them in `uv` - improves portability and performance (especially on macOS). - - However, in some cases, you may want to use the platform's native certificate store, - especially if you're relying on a corporate trust root (e.g., for a mandatory proxy) - that's included in your system's certificate store. - - [env: UV_NATIVE_TLS=] - + Whether to load TLS certificates from the platform's native certificate store [env: + UV_NATIVE_TLS=] --offline Disable network access, relying only on locally cached data and locally available files - --python-preference - Whether to prefer using Python from uv or on the system - - Possible values: - - only-managed: Only use managed Python installations; never use system Python - installations - - installed: Prefer installed Python installations, only download managed Python - installations if no system Python installation is found - - managed: Prefer managed Python installations over system Python installations, even - if fetching is required - - system: Prefer system Python installations over managed Python installations - - only-system: Only use system Python installations; never use managed Python - installations - + Whether to prefer using Python from uv or on the system [possible values: only-managed, + installed, managed, system, only-system] --python-fetch - Whether to automatically download Python when required - - Possible values: - - automatic: Automatically fetch managed Python installations when needed - - manual: Do not automatically fetch managed Python installations; require explicit - installation - + Whether to automatically download Python when required [possible values: automatic, + manual] -n, --no-cache - Avoid reading from or writing to the cache - - [env: UV_NO_CACHE=] - + Avoid reading from or writing to the cache [env: UV_NO_CACHE=] --cache-dir [CACHE_DIR] - Path to the cache directory. - - Defaults to `$HOME/Library/Caches/uv` on macOS, `$XDG_CACHE_HOME/uv` or `$HOME/.cache/uv` - on Linux, and `{FOLDERID_LocalAppData}/uv/cache` on Windows. - - [env: UV_CACHE_DIR=] - + Path to the cache directory [env: UV_CACHE_DIR=] --config-file - The path to a `uv.toml` file to use for configuration - - [env: UV_CONFIG_FILE=] - + The path to a `uv.toml` file to use for configuration [env: UV_CONFIG_FILE=] -h, --help - Print help (see a summary with '-h') - + Print help -V, --version Print version @@ -719,7 +551,7 @@ fn help_unknown_subcommand() { Usage: uv [OPTIONS] - For more information, try '--help'. + For more information, try 'help'. "###); uv_snapshot!(context.filters(), context.help().arg("foo").arg("bar"), @r###" @@ -732,7 +564,7 @@ fn help_unknown_subcommand() { Usage: uv [OPTIONS] - For more information, try '--help'. + For more information, try 'help'. "###); } @@ -750,7 +582,7 @@ fn help_unknown_subsubcommand() { Usage: uv python [OPTIONS] - For more information, try '--help'. + For more information, try 'help'. "###); } @@ -768,7 +600,7 @@ fn help_with_global_option() { Usage: uv [OPTIONS] - For more information, try '--help'. + For more information, try 'help'. "###); } @@ -786,7 +618,7 @@ fn help_with_help() { Usage: uv [OPTIONS] - For more information, try '--help'. + For more information, try 'help'. "###); } @@ -804,6 +636,6 @@ fn help_with_version() { Usage: uv [OPTIONS] - For more information, try '--help'. + For more information, try 'help'. "###); } diff --git a/crates/uv/tests/pip_compile.rs b/crates/uv/tests/pip_compile.rs index 5c2e3b3c7f89..9f71a9839b18 100644 --- a/crates/uv/tests/pip_compile.rs +++ b/crates/uv/tests/pip_compile.rs @@ -997,8 +997,6 @@ optional-dependencies.foo = [ ----- stderr ----- error: invalid value 'invalid name!' for '--extra ': Extra names must start and end with a letter or digit and may only contain -, _, ., and alphanumeric characters - - For more information, try '--help'. "### ); @@ -1188,8 +1186,6 @@ fn compile_python_invalid_version() -> Result<()> { ----- stderr ----- error: invalid value '3.7.x' for '--python-version ': Python version `3.7.x` could not be parsed: after parsing '3.7', found '.x', which is not part of a valid version - - For more information, try '--help'. "### ); @@ -1213,8 +1209,6 @@ fn compile_python_dev_version() -> Result<()> { ----- stderr ----- error: invalid value '3.7-dev' for '--python-version ': Python version `3.7-dev` is a development release - - For more information, try '--help'. "### ); @@ -2422,8 +2416,6 @@ optional-dependencies.bar = [ error: the argument '--all-extras' cannot be used with '--extra ' Usage: uv pip compile --cache-dir [CACHE_DIR] --all-extras --exclude-newer ... - - For more information, try '--help'. "### ); @@ -2555,8 +2547,6 @@ fn compile_exclude_newer() -> Result<()> { ----- stderr ----- error: invalid value '2022-04-04+02:00' for '--exclude-newer ': `2022-04-04+02:00` is neither a valid date (trailing input) nor a valid datetime (input contains invalid characters) - - For more information, try '--help'. "### ); diff --git a/crates/uv/tests/pip_install.rs b/crates/uv/tests/pip_install.rs index 14f2f829c85d..0e2418d11882 100644 --- a/crates/uv/tests/pip_install.rs +++ b/crates/uv/tests/pip_install.rs @@ -273,7 +273,7 @@ fn missing_pip() { Usage: uv [OPTIONS] - For more information, try '--help'. + For more information, try 'help'. "###); } diff --git a/crates/uv/tests/pip_uninstall.rs b/crates/uv/tests/pip_uninstall.rs index 94d164b6f317..a8aba5481586 100644 --- a/crates/uv/tests/pip_uninstall.rs +++ b/crates/uv/tests/pip_uninstall.rs @@ -28,8 +28,6 @@ fn no_arguments() -> Result<()> { > Usage: uv pip uninstall > - - For more information, try '--help'. "### );