TeXitoi / structopt

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

#[structopt(allow_hyphen_values = true]) compiles but does not work #510

Closed nstinus closed 2 years ago

nstinus commented 2 years ago

Hi,

I am trying to allow an i32 positional argument and I can't parse negative inputs. I have tried using

#[structopt(allow_hyphen_values = true]) 
arg: i32,

to no avail.

I'll greatly appreciate any help.

Thanks!

DominikRusso commented 2 years ago

Try #[structopt(settings = &[structopt::clap::AppSettings::AllowNegativeNumbers])] on a top level field.

For example:

use structopt::clap::AppSettings;
use structopt::StructOpt;

#[derive(StructOpt, Debug)]
pub enum Subcommand {
    // ...

    #[structopt(alias = "bri", settings = &[AppSettings::AllowNegativeNumbers])]
    Brightness {
        brightness: String,
        lights: Vec<String>,
    },

    // ...
}
TeXitoi commented 2 years ago

Yeah, allow_hypen_values is for options, not for args.

Also, please provide a complete compiling example when you have a question, explaining the actual behavior and the expected behavior. It will be much easier to understand the question.