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
38
39
40
41
42
43
44
45
//! Clap commander
use clap::{App, AppSettings};
use crate::{
    cmds::{
        Command,
        StatCommand,
        ListCommand,
        CacheCommand,
    },
    flag::{
        Flag,
        Debug,
    }
};

/// get maches
pub fn main() {
    let m = App::new("leetcode")
        .author("clearloop <udtrokia@163.com>")
        .version("0.1.6")
        .about("Leet your code in command-line.")
        .subcommands(vec![
            CacheCommand::usage().display_order(1),
            ListCommand::usage().display_order(2),
            StatCommand::usage().display_order(3),
        ])
        .arg(Debug::usage())
        .setting(AppSettings::ArgRequiredElseHelp)
        .get_matches();

    if m.is_present("debug") {
        Debug::handler();
    } else {
        env_logger::from_env(env_logger::Env::new().default_filter_or("info"))
        .format_timestamp(None)
        .init();
    }

    match m.subcommand() {
        ("list", Some(sub_m)) => ListCommand::handler(sub_m),
        ("stat", Some(sub_m)) => StatCommand::handler(sub_m),
        ("cache", Some(sub_m)) => CacheCommand::handler(sub_m),
        _ => {}
    }
}