boilerplate for rust CLI apps
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.
cli-app-base/examples/minimal.rs

41 lines
768 B

#[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(())
}