TeXitoi / structopt

Parse command line arguments by defining a struct.
Other
2.7k stars 149 forks source link

Duplicate short option gives runtime error, wouldn't it be cool, if it was compile time error #500

Closed typetetris closed 2 years ago

typetetris commented 2 years ago

Something like

use structopt::StructOpt;

#[derive(Debug,StructOpt)]
struct Opt {
      #[structopt(short, long)]
      fnord: u16,

      #[structopt(short, long)]
      file: String
}

gives an error at runtime of the program.

It would be way cooler, if it was a compile time error.

If you agree, I could look into trying to implement this.

TeXitoi commented 2 years ago

I doubt this particular example will panic. Edit: ho, OK, short argument, yep, it'll panic.

There is no easy way of checking you use the same name several times. Basic case is double, bit when you add flatten and friends, it can become a nightmare. I don't want complicated code to do compile time check that would be catch in all case with a basic test. Now, if the code is really trivial, why not, but I doubt.

TeXitoi commented 2 years ago

This is an enhancement, and structopt is now feature frozen.