mirror of
https://github.com/clap-rs/clap
synced 2024-12-13 06:12:40 +00:00
Added auto-version example
This commit is contained in:
parent
44830a0155
commit
b0a47a5004
1 changed files with 20 additions and 0 deletions
20
examples/09_AutoVersion.rs
Normal file
20
examples/09_AutoVersion.rs
Normal file
|
@ -0,0 +1,20 @@
|
|||
extern crate clap;
|
||||
|
||||
use clap::App;
|
||||
|
||||
fn main() {
|
||||
// You can have clap pull the application version directly from your Cargo.toml starting with
|
||||
// clap v0.4.14 on crates.io (or master#a81f915 on github)
|
||||
//
|
||||
// Thanks to https://github.com/jhelwig for pointing this out
|
||||
let version = format!("{}.{}.{}{}",
|
||||
env!("CARGO_PKG_VERSION_MAJOR"),
|
||||
env!("CARGO_PKG_VERSION_MINOR"),
|
||||
env!("CARGO_PKG_VERSION_PATCH"),
|
||||
option_env!("CARGO_PKG_VERSION_PRE").unwrap_or(""));
|
||||
|
||||
let matches = App::new("myapp").about("does awesome things").version(&version[..]).get_matches();
|
||||
|
||||
// running the this app with the -v or --version will display whatever version is in your
|
||||
// Cargo.toml, the default being: myapp 0.0.1
|
||||
}
|
Loading…
Reference in a new issue