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
use crate::annotator;
use crate::Config;
use clap::Parser;
use std::path::PathBuf;

#[derive(Parser)]
#[clap(version, about)]
pub struct Cli {
    #[clap(long, short, parse(from_os_str))]
    /// Use the configuration from <CONFIG>. <CONFIG> is a path starting from
    /// your current working directory
    pub config: Option<PathBuf>,
    /// Disallow interactions during the focus period
    #[clap(short, long)]
    pub silent: bool,
    /// Annotator mode, a guide to find processes names
    #[clap(short, long)]
    pub annotate: bool,
    /// Annotator mode, a guide to find processes names, without filtering for user
    #[clap(long)]
    pub annotate_no_user: bool,
}

pub enum InteractType {
    NormalRun,
    SilentRun,
}

pub fn interpret_args() -> (Config, InteractType, PathBuf) {
    let cli = Cli::parse();
    if cli.annotate | cli.annotate_no_user {
        annotator::annotator(!cli.annotate_no_user);
        (Config::default(), InteractType::NormalRun, PathBuf::new())
    } else {
        let (config, path) = Config::get_or_create(cli.config);
        let interactive = match cli.silent {
            true => InteractType::SilentRun,
            false => InteractType::NormalRun,
        };
        (config, interactive, path)
    }
}