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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
use crate::config::Config;
use clap::Parser;
use lemmeknow::Identifier;
use log::trace;
#[derive(Parser)]
#[command(author = "Bee <bee@skerritt.blog>", about, long_about = None)]
pub struct Opts {
    #[arg(short, long)]
    text: String,
    #[arg(short, long, action = clap::ArgAction::Count)]
    verbose: u8,
    #[arg(short, long)]
    disable_human_checker: bool,
    #[arg(short, long)]
    cracking_timeout: u32,
}
pub fn parse_cli_args() -> (String, Config) {
    let opts: Opts = Opts::parse();
    let min_log_level = match opts.verbose {
        0 => "Warn",
        1 => "Info",
        2 => "Debug",
        _ => "Trace",
    };
    env_logger::init_from_env(
        env_logger::Env::default().filter_or(env_logger::DEFAULT_FILTER_ENV, min_log_level),
    );
    trace!("Program was called with CLI 😉");
    trace!("Parsed the arguments");
    cli_args_into_config_struct(opts)
}
fn cli_args_into_config_struct(opts: Opts) -> (String, Config) {
    (
        opts.text,
        Config {
            verbose: opts.verbose,
            lemmeknow_config: Identifier::default(),
            human_checker_on: !opts.disable_human_checker,
            offline_mode: true,
            timeout: opts.cracking_timeout,
        },
    )
}