2020-01-09 03:56:27 +00:00
|
|
|
use clap::{crate_version, App};
|
2015-03-24 02:53:33 +00:00
|
|
|
|
|
|
|
fn main() {
|
|
|
|
// You can have clap pull the application version directly from your Cargo.toml starting with
|
2015-04-19 18:06:08 +00:00
|
|
|
// clap v0.4.14 on crates.io (or master#a81f915 on github). Using Rust's env! macro like this:
|
|
|
|
//
|
|
|
|
// let version = format!("{}.{}.{}{}",
|
|
|
|
// env!("CARGO_PKG_VERSION_MAJOR"),
|
|
|
|
// env!("CARGO_PKG_VERSION_MINOR"),
|
|
|
|
// env!("CARGO_PKG_VERSION_PATCH"),
|
2015-10-01 01:45:35 +00:00
|
|
|
// option_env!("CARGO_PKG_VERSION_PRE").unwrap_or(""));
|
2015-04-19 18:06:08 +00:00
|
|
|
//
|
2015-10-01 01:45:35 +00:00
|
|
|
// Starting from v0.6.6 on crates.io you can also use the crate_version!() macro instead of
|
2015-04-19 18:06:08 +00:00
|
|
|
// manually using the env!() macros. Under the hood, the macro uses this exact method to get
|
|
|
|
// the version.
|
2015-03-24 02:53:33 +00:00
|
|
|
//
|
|
|
|
// Thanks to https://github.com/jhelwig for pointing this out
|
2015-08-30 20:16:35 +00:00
|
|
|
App::new("myapp")
|
|
|
|
.about("does awesome things")
|
2018-11-14 17:05:06 +00:00
|
|
|
// use crate_version! to pull the version number
|
|
|
|
.version(crate_version!())
|
|
|
|
.get_matches();
|
2015-03-24 02:53:33 +00:00
|
|
|
|
2017-05-11 05:48:25 +00:00
|
|
|
// running this app with the -V or --version will display whatever version is in your
|
2015-03-24 02:53:33 +00:00
|
|
|
// Cargo.toml, the default being: myapp 0.0.1
|
2015-06-17 00:46:11 +00:00
|
|
|
}
|