clap-rs / clap

A full featured, fast Command Line Argument Parser for Rust

Home Page:docs.rs/clap

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add the Ability to Display Visible Aliases for PossibleValues

naftulikay opened this issue · comments

Please complete the following tasks

Clap Version

master

Describe your use case

Consider the following use-case:

use clap::{Parser, ValueEnum};

#[derive(Debug, Clone, Parser)]
pub struct Args {
    /// The environment to execute in
    #[arg(short = 'e', long = "env")]
    pub env: Env,
}

#[derive(Debug, Clone, ValueEnum)]
pub enum Env {
    /// The development environment
    #[value(aliases = ["dev", "d"])]
    Development,
    /// The staging environment
    Staging,
    /// The production environment
    #[value(aliases = ["prod"])]
    Production,
}

In this case, #[value(aliases = ["prod"]) adds an alias, but this alias is hidden, regardless of whether hide is set or not. The existing API allows these aliases but does not display them in -h or --help output.

Describe the solution you'd like

To this end, I propose that we add a visible_alias and visible_aliases function to PossibleValue to allow users to add visible aliases which will show up in help text. PR is incoming.

Alternatives, if applicable

This seems to be the most direct way of doing this.

Additional Context

No response

This seems to be the same as #4416, closing in favor of that. If there is a reason to keep this open, let us know!