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

Why do all issues asking for prefix are closed?

DimanNe opened this issue · comments

Please complete the following tasks

Clap Version

4.5.0

Describe your use case

I know there are: #3513, #3117, #5050, #4556, but there are no solutions (in the issues).

I personally came across this limitation too.

I have multiple ways to specify password:

#[derive(Debug, clap::Args)]
#[group(required = true, multiple = false)]
struct ReqPassphrase {
   #[arg(long, default_value_t)]
   passphrase: String,

   #[arg(long)]
   pass_stdin: bool,

   pass_fido: bool,

   pass_fido_rp: String,

   #[arg(long)]
   pass_fido_uid: Option<String>,
}

and some subcommands need to know old passphrase and new:

   AddKey {
      #[command(flatten)]
      new_passphrase: ReqPassphrase,

      #[command(flatten)]
      old_passphrase: ReqPassphrase,
   },

which obviously fails to compile.

How can I implement this without copy-paste? Why are all the issues above closed?

Describe the solution you'd like

The simplest one: is to provide prefix as an attribute, for example in my case I could provide prefix old_ and pass_stdin would become old_pass_stdin

Alternatives, if applicable

No response

Additional Context

No response

2 of the 4 linked issues are open. The 2 linked issues list their reason for being closed.

If the reason the issue is closed is unclear, the thing to do would be to post on that issue, rather than open a new issue.

Going to close in favor of the linked issues so we can keep the discussion in one place, rather than creating more places.