rust-lang-nursery / rust-cookbook

https://rust-lang-nursery.github.io/rust-cookbook
Creative Commons Zero v1.0 Universal
2.25k stars 284 forks source link

Update chapter 2.1 Clap basic #616

Open c12i opened 3 years ago

c12i commented 3 years ago

The current code example will not compile if you use the clap v3.0.0-beta.2, the version indicated above it. In this version of clap, the Arg struct no longer has the with_name or the help methods. Instead, use the new and about methods respectively:

//...
let matches = App::new("My Test Program")
        .version("0.1.0")
        .author("Collins Muriuki <murerwacollins@gmail.com>")
        .about("Teaches argument parsing")
        .arg(Arg::new("file")
            .short('f')
            .long("file")
            .takes_value(true)
            .about("A cool file"))
//...

Also, the newer short method now accepts a char type rather than &str as a parameter.