1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
//! Flags in leetcode-cli
//!
//! ```sh
//! FLAGS:
//!     -d, --debug      debug mode
//!     -h, --help       Prints help information
//!     -V, --version    Prints version information
//! ```
use clap::Arg;
use env_logger::Env;
use crate::err::Error;

/// abstract flag traits
pub trait Flag {
    fn usage<'a, 'f>() -> Arg<'a, 'f>;
    fn handler() -> Result<(), Error>;
}

/// Debug logger
pub struct Debug;

impl Flag for Debug {
    fn usage<'a, 'f>() -> Arg<'a, 'f> {
        Arg::with_name("debug")
            .short("d")
            .long("debug")
            .help("debug mode")
    }

    fn handler() -> Result<(), Error>{
        env_logger::from_env(
            Env::default().default_filter_or("leetcode")
        ).init();

        Ok(())
    }
}