Show help specific options in `uv help` (#5516)

## Summary

Resolves #5221 

## Test Plan

Test case included.
This commit is contained in:
eth3lbert 2024-08-01 01:10:57 +08:00 committed by GitHub
parent ef84380954
commit 54398fa7bc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 16 additions and 2 deletions

View File

@ -4,6 +4,7 @@ use std::path::PathBuf;
use std::str::FromStr; use std::str::FromStr;
use anyhow::{anyhow, Result}; use anyhow::{anyhow, Result};
use clap::builder::styling::Style;
use clap::{Args, Parser, Subcommand}; use clap::{Args, Parser, Subcommand};
use distribution_types::{FlatIndexLocation, IndexUrl}; use distribution_types::{FlatIndexLocation, IndexUrl};
@ -246,10 +247,20 @@ pub enum Commands {
#[command(alias = "--generate-shell-completion", hide = true)] #[command(alias = "--generate-shell-completion", hide = true)]
GenerateShellCompletion { shell: clap_complete_command::Shell }, GenerateShellCompletion { shell: clap_complete_command::Shell },
/// Display documentation for a command. /// 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 = "\ #[command(help_template = "\
{about-with-newline} {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), Help(HelpArgs),
} }

View File

@ -678,6 +678,9 @@ fn help_with_help() {
Usage: uv help [OPTIONS] [COMMAND]... Usage: uv help [OPTIONS] [COMMAND]...
Options:
--no-pager Disable pager when printing help
----- stderr ----- ----- stderr -----
"###); "###);
} }