Skip to content

Commit

Permalink
docs: Fix outdated short comment
Browse files Browse the repository at this point in the history
Noticed as part of clap-rs#4311
  • Loading branch information
epage committed Sep 30, 2022
1 parent 0bea4f2 commit 7584030
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions src/builder/arg.rs
Expand Up @@ -120,9 +120,9 @@ impl Arg {
/// Sets the short version of the argument without the preceding `-`.
///
/// By default `V` and `h` are used by the auto-generated `version` and `help` arguments,
/// respectively. You may use the uppercase `V` or lowercase `h` for your own arguments, in
/// which case `clap` simply will not assign those to the auto-generated
/// `version` or `help` arguments.
/// respectively. You will need to disable the auto-generated flags
/// ([`disable_help_flag`][crate::Command::disable_help_flag],
/// [`disable_version_flag`][crate::Command::disable_version_flag]) and define your own.
///
/// # Examples
///
Expand All @@ -141,6 +141,25 @@ impl Arg {
///
/// assert_eq!(m.get_one::<String>("config").map(String::as_str), Some("file.toml"));
/// ```
///
/// To use `-h` for your own flag and still have help:
/// ```rust
/// # use clap::{Command, Arg, ArgAction};
/// let m = Command::new("prog")
/// .disable_help_flag(true)
/// .arg(Arg::new("host")
/// .short('h')
/// .long("help"))
/// .arg(Arg::new("help")
/// .long("help")
/// .global(true)
/// .action(ArgAction::Help))
/// .get_matches_from(vec![
/// "prog", "-h", "wikipedia.org"
/// ]);
///
/// assert_eq!(m.get_one::<String>("host").map(String::as_str), Some("wikipedia.org"));
/// ```
#[inline]
#[must_use]
pub fn short(mut self, s: impl IntoResettable<char>) -> Self {
Expand Down

0 comments on commit 7584030

Please sign in to comment.