TeXitoi / structopt

Parse command line arguments by defining a struct.
Other
2.71k stars 150 forks source link

Alias' #467

Closed Milo123459 closed 3 years ago

Milo123459 commented 3 years ago
#[structopt(parse(from_os_str), default_value = ".glitterrc", long, visible_alias = "rc")]

^ This is my code.

When typing cargo run -- --help the alias doesn't appear there.

Is there a fix or am I doing it wrong?

TeXitoi commented 3 years ago
use std::path::PathBuf;
use structopt::StructOpt;

#[derive(Debug, StructOpt)]
struct Opt {
    #[structopt(
        parse(from_os_str),
        default_value = ".glitterrc",
        long,
        visible_alias = "rc"
    )]
    conf: PathBuf,
}

fn main() {
    println!("{:?}", Opt::from_args());
}
cargo run --manifest-path /home/gpinot/dev/test-rs/Cargo.toml -- --help
    Blocking waiting for file lock on build directory
   Compiling test-rs v0.1.0 (/home/gpinot/dev/test-rs)
    Finished dev [unoptimized + debuginfo] target(s) in 0.60s
     Running `target/debug/test-rs --help`
test-rs 0.1.0

USAGE:
    test-rs [OPTIONS]

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

OPTIONS:
        --conf <conf>     [default: .glitterrc]  [aliases: rc]

Works here. Please provide a complete example.

Milo123459 commented 3 years ago

In the help command, I don't see it.

Milo123459 commented 3 years ago

Nevermind, I had to rebuild.