Show ValueEnum Aliases in Help Output in Clap

I have a simple example on the Playground:

use clap; // 4.5.4
use clap::{Parser, ValueEnum};

#[derive(Debug, Clone, Parser)]
pub struct Args {
    /// The target environment
    #[arg(long = "env", hide_possible_values = false)]
    pub env: Env,
}

#[derive(Debug, Clone, ValueEnum)]
pub enum Env {
    // FIXME how do I unhide this alias?
    /// dev environment
    #[value(alias("dev"), hide = false)]
    Development,
    // FIXME how do I unhide this alias?
    /// prod environment
    #[value(alias("prod"), hide = false)]
    Production,
}

fn main() {
    Args::parse_from(&[std::env::args().nth(0).unwrap().as_str(), "--help"]);
}

Running this does not show the aliases:

Usage: playground --env <ENV>

Options:
      --env <ENV>
          The target environment

          Possible values:
          - development: dev environment
          - production:  prod environment

  -h, --help
          Print help (see a summary with '-h')

I want the aliases that I am specifying to show up in the --help docs, but I can't seem to find a way to make this possible.

Is there a way to "unhide" the aliases so they show up?

Glancing at clap's help formatting code it doesn't seem possible, I suggest filling an issue or a opening PR.

I opened a PR and added the feature here: Add Visible Aliases for PossibleValue by naftulikay · Pull Request #5480 · clap-rs/clap · GitHub

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.