Add verbose flag
This commit is contained in:
20
src/main.rs
20
src/main.rs
@ -10,6 +10,7 @@ mod util;
|
|||||||
use actions::{list, show_plan, sync};
|
use actions::{list, show_plan, sync};
|
||||||
use chrono::{DateTime, FixedOffset};
|
use chrono::{DateTime, FixedOffset};
|
||||||
use clap::{crate_version, Parser};
|
use clap::{crate_version, Parser};
|
||||||
|
use log::LevelFilter;
|
||||||
use remote::Remote;
|
use remote::Remote;
|
||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
@ -21,6 +22,14 @@ pub type FileList = BTreeMap<TimeStamp, String>;
|
|||||||
#[derive(Parser)]
|
#[derive(Parser)]
|
||||||
#[clap(version = crate_version!())]
|
#[clap(version = crate_version!())]
|
||||||
pub struct Opt {
|
pub struct Opt {
|
||||||
|
/// Log more stuff
|
||||||
|
#[clap(long, short, parse(from_occurrences))]
|
||||||
|
verbose: u8,
|
||||||
|
|
||||||
|
/// Do not output anything but errors.
|
||||||
|
#[clap(long, short)]
|
||||||
|
quiet: bool,
|
||||||
|
|
||||||
/// The path of the backup directory on the local filesystem
|
/// The path of the backup directory on the local filesystem
|
||||||
#[clap(short = 'l', long)]
|
#[clap(short = 'l', long)]
|
||||||
path: PathBuf,
|
path: PathBuf,
|
||||||
@ -64,7 +73,16 @@ pub enum Action {
|
|||||||
fn main() -> anyhow::Result<()> {
|
fn main() -> anyhow::Result<()> {
|
||||||
let opt = Opt::parse();
|
let opt = Opt::parse();
|
||||||
|
|
||||||
pretty_env_logger::init();
|
let log_level = match opt.verbose {
|
||||||
|
0 if opt.quiet => LevelFilter::Error,
|
||||||
|
0 => LevelFilter::Info,
|
||||||
|
1 => LevelFilter::Debug,
|
||||||
|
2.. => LevelFilter::Trace,
|
||||||
|
};
|
||||||
|
|
||||||
|
pretty_env_logger::formatted_builder()
|
||||||
|
.filter(None, log_level)
|
||||||
|
.init();
|
||||||
|
|
||||||
match opt.action {
|
match opt.action {
|
||||||
Action::Backup { all } => sync::run(&opt, all)?,
|
Action::Backup { all } => sync::run(&opt, all)?,
|
||||||
|
|||||||
Reference in New Issue
Block a user