You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
768 B
42 lines
768 B
5 years ago
|
#[macro_use]
|
||
|
extern crate serde_derive;
|
||
|
#[macro_use]
|
||
|
extern crate log;
|
||
|
|
||
|
use clap::ArgMatches;
|
||
|
use clappconfig::AppConfig;
|
||
|
use failure::Fallible;
|
||
|
|
||
|
#[derive(Serialize, Deserialize, Debug, Default)]
|
||
|
#[serde(default)]
|
||
|
struct Config {
|
||
|
foo: u32,
|
||
|
bar: u32,
|
||
|
}
|
||
|
|
||
|
impl AppConfig for Config {
|
||
|
type Init = Config;
|
||
|
|
||
|
fn logging(&self) -> &str {
|
||
|
"info"
|
||
|
}
|
||
|
|
||
|
fn configure<'a>(self, _clap: &ArgMatches<'a>) -> Fallible<Config> {
|
||
|
Ok(self)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
fn main() -> Fallible<()> {
|
||
|
let cfg = Config::init("Foo", "examples/foo.json", None)?;
|
||
|
|
||
|
trace!("Trace message");
|
||
|
debug!("Debug message");
|
||
|
info!("Info message");
|
||
|
warn!("Warn message");
|
||
|
error!("Error message");
|
||
|
|
||
|
println!("Welcome to foo, config:\n{:#?}", cfg);
|
||
|
|
||
|
Ok(())
|
||
|
}
|