Parse command-line-arguments

Use command-line-arguments to set the config file path and the log
level.
This commit is contained in:
finga 2023-01-24 01:20:42 +01:00
parent d37f31dd8a
commit 21396daf83
4 changed files with 171 additions and 0 deletions

15
src/args.rs Normal file
View file

@ -0,0 +1,15 @@
use clap::Parser;
use std::path::PathBuf;
use tracing::Level;
#[derive(Parser)]
#[command(author, version, about)]
pub struct Args {
/// Use a custom config file
#[arg(short, long, value_name = "FILE")]
config: Option<PathBuf>,
/// Set a log level
#[arg(short, long, value_name = "LEVEL", default_value_t = Level::INFO)]
pub log_level: Level,
}

View file

@ -1,4 +1,5 @@
use anyhow::Result;
use clap::Parser;
use diesel::{
prelude::*,
r2d2::{ConnectionManager, Pool, PooledConnection},
@ -8,10 +9,12 @@ use std::{env, thread::park_timeout};
use time::{Duration, OffsetDateTime};
use tracing::{debug, info, trace};
mod args;
mod config;
mod models;
mod schema;
use args::Args;
use config::Config;
use models::{NewReminder, Reminder};
@ -54,6 +57,12 @@ fn remind(
}
fn main() -> Result<()> {
let args = Args::parse();
if env::var("RUST_LOG").is_err() {
env::set_var("RUST_LOG", format!("{}", args.log_level));
}
tracing_subscriber::fmt::init();
info!(