TeXitoi / structopt

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

Specify order of arguments? #501

Closed fzyzcjy closed 2 years ago

fzyzcjy commented 2 years ago

Hi thanks for the lib! I wonder how can I force the order of options? Currently it is in alphabetical order.

TeXitoi commented 2 years ago

You mean in the help message? See https://docs.rs/clap/2.33.3/clap/enum.AppSettings.html DeriveDisplayOrder

fzyzcjy commented 2 years ago

Thanks!

fzyzcjy commented 2 years ago

Hmm it does not work:

#[derive(StructOpt, Debug, PartialEq, Deserialize)]
#[structopt(setting(AppSettings::DeriveDisplayOrder))]
pub struct RawOpts {
    /// Path of input Rust code
    #[structopt(short, long)]
    pub rust_input: String,
    /// Path of output generated Dart code
    #[structopt(short, long)]
    pub dart_output: String,
...
}

results

(base) ➜  frb_codegen git:(master) ✗ cargo run -- --help
   Compiling flutter_rust_bridge_codegen v1.0.0 (/Users/tom/QAPMain/TomLib/flutter_rust_bridge/frb_codegen)
    Finished dev [unoptimized + debuginfo] target(s) in 1.65s
     Running `target/debug/flutter_rust_bridge_codegen --help`
flutter_rust_bridge_codegen 1.0.0

USAGE:
    flutter_rust_bridge_codegen [OPTIONS] --dart-output <dart-output> --rust-input <rust-input>

FLAGS:
    -h, --help       Prints help information
    -V, --version    Prints version information

OPTIONS:
    -r, --rust-input <rust-input>                              Path of input Rust code
    -d, --dart-output <dart-output>                            Path of output generated Dart code
    -c, --c-output <c-output>                                  Path of output generated C header
        --rust-crate-dir <rust-crate-dir>                      Crate directory for your Rust project
        --rust-output <rust-output>                            Path of output generated Rust code
        --class-name <class-name>                              Generated class name
        --dart-format-line-length <dart-format-line-length>    Line length for dart formatting

I want the order of

USAGE:
    flutter_rust_bridge_codegen [OPTIONS] --dart-output <dart-output> --rust-input <rust-input>

to be same as what is declared in rust.

TeXitoi commented 2 years ago

Please see the clap documentation as this is not managed by structopt but clap. I think that's not possible, but you can, at a last resort, write the help message by hand.

fzyzcjy commented 2 years ago

Ah... thank you!