fix API to not report own crate version if None given
This commit is contained in:
+1
-1
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "clappconfig"
|
||||
version = "0.3.1"
|
||||
version = "0.4.0"
|
||||
authors = ["Ondřej Hruška <ondra@ondrovo.com>"]
|
||||
edition = "2018"
|
||||
license = "MIT"
|
||||
|
||||
+5
-1
@@ -30,7 +30,11 @@ impl AppConfig for Config {
|
||||
}
|
||||
|
||||
fn main() -> anyhow::Result<()> {
|
||||
let cfg = Config::init("Foo Example", "examples/foo.json", None)?;
|
||||
let cfg = Config::init(
|
||||
"Foo Example",
|
||||
"examples/foo.json",
|
||||
env!("CARGO_PKG_VERSION"),
|
||||
)?;
|
||||
|
||||
trace!("Trace message");
|
||||
debug!("Debug message");
|
||||
|
||||
+1
-1
@@ -149,7 +149,7 @@ fn main() -> anyhow::Result<()> {
|
||||
env!("CARGO_PKG_AUTHORS")
|
||||
);
|
||||
|
||||
let main = Config::init("Rot-N", "rotn_config.json", Some(&version))?;
|
||||
let main = Config::init("Rot-N", "rotn_config.json", &version)?;
|
||||
|
||||
// rot13
|
||||
|
||||
|
||||
+3
-2
@@ -62,8 +62,9 @@ pub trait AppConfig: Sized + Serialize + DeserializeOwned + Debug + Default {
|
||||
fn configure<'a>(self, _clap: &clap::ArgMatches<'a>) -> anyhow::Result<Self::Init>;
|
||||
|
||||
/// Initialize the app
|
||||
fn init(name: &str, cfg_file_name: &str, version: Option<&str>) -> anyhow::Result<Self::Init> {
|
||||
let version = version.unwrap_or_else(|| env!("CARGO_PKG_VERSION"));
|
||||
///
|
||||
/// Use `env!("CARGO_PKG_VERSION")` to get a version string from Cargo.toml
|
||||
fn init(name: &str, cfg_file_name: &str, version: &str) -> anyhow::Result<Self::Init> {
|
||||
let clap = clap::App::new(name)
|
||||
.arg(
|
||||
clap::Arg::with_name("config")
|
||||
|
||||
Reference in New Issue
Block a user