fix API to not report own crate version if None given
This commit is contained in:
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "clappconfig"
|
name = "clappconfig"
|
||||||
version = "0.3.1"
|
version = "0.4.0"
|
||||||
authors = ["Ondřej Hruška <ondra@ondrovo.com>"]
|
authors = ["Ondřej Hruška <ondra@ondrovo.com>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
|
|||||||
+5
-1
@@ -30,7 +30,11 @@ impl AppConfig for Config {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn main() -> anyhow::Result<()> {
|
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");
|
trace!("Trace message");
|
||||||
debug!("Debug message");
|
debug!("Debug message");
|
||||||
|
|||||||
+1
-1
@@ -149,7 +149,7 @@ fn main() -> anyhow::Result<()> {
|
|||||||
env!("CARGO_PKG_AUTHORS")
|
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
|
// 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>;
|
fn configure<'a>(self, _clap: &clap::ArgMatches<'a>) -> anyhow::Result<Self::Init>;
|
||||||
|
|
||||||
/// Initialize the app
|
/// 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)
|
let clap = clap::App::new(name)
|
||||||
.arg(
|
.arg(
|
||||||
clap::Arg::with_name("config")
|
clap::Arg::with_name("config")
|
||||||
|
|||||||
Reference in New Issue
Block a user