From 54398fa7bc4ecd41d09eab80b76e9ab288810ac0 Mon Sep 17 00:00:00 2001 From: eth3lbert Date: Thu, 1 Aug 2024 01:10:57 +0800 Subject: [PATCH] Show help specific options in `uv help` (#5516) ## Summary Resolves #5221 ## Test Plan Test case included. --- crates/uv-cli/src/lib.rs | 15 +++++++++++++-- crates/uv/tests/help.rs | 3 +++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/crates/uv-cli/src/lib.rs b/crates/uv-cli/src/lib.rs index 0ab93ca236e7..717596e05c9b 100644 --- a/crates/uv-cli/src/lib.rs +++ b/crates/uv-cli/src/lib.rs @@ -4,6 +4,7 @@ use std::path::PathBuf; use std::str::FromStr; use anyhow::{anyhow, Result}; +use clap::builder::styling::Style; use clap::{Args, Parser, Subcommand}; use distribution_types::{FlatIndexLocation, IndexUrl}; @@ -246,10 +247,20 @@ pub enum Commands { #[command(alias = "--generate-shell-completion", hide = true)] GenerateShellCompletion { shell: clap_complete_command::Shell }, /// Display documentation for a command. + // To avoid showing the global options when displaying help for the help command, we are + // responsible for maintaining the options using the `after_help`. #[command(help_template = "\ {about-with-newline} -{usage-heading} {usage} -")] +{usage-heading} {usage}{after-help} +", + after_help = format!("\ +{heading}Options:{heading:#} + {option}--no-pager{option:#} Disable pager when printing help +", + heading = Style::new().bold().underline(), + option = Style::new().bold(), + ), + )] Help(HelpArgs), } diff --git a/crates/uv/tests/help.rs b/crates/uv/tests/help.rs index 123e7a05b431..86a44f913a39 100644 --- a/crates/uv/tests/help.rs +++ b/crates/uv/tests/help.rs @@ -678,6 +678,9 @@ fn help_with_help() { Usage: uv help [OPTIONS] [COMMAND]... + Options: + --no-pager Disable pager when printing help + ----- stderr ----- "###); }