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
use clap::ArgMatches;

pub mod command;

/// Command line interface for the collector.
///
/// Returns the matches from the command line arguments.
#[allow(clippy::cognitive_complexity)]
#[must_use]
pub fn clargs() -> ArgMatches {
    use std::path::PathBuf;

    use clap::{arg, command, value_parser, ArgAction, Command};

    let command = command!()
        .subcommand(
            Command::new("init")
                .about("Initialize the database tables")
                .arg(
                    arg!(config: -c --config <FILE> "optional path to the configuration file")
                        .value_parser(value_parser!(PathBuf)),
                ),
        )
        .subcommand(
            Command::new("drop")
                .about("Remove the database tables")
                .arg(arg!(all: -a --all "remove tables for all coins").action(ArgAction::SetTrue))
                .arg(
                    arg!(config: -c --config <FILE> "optional path to the configuration file")
                        .value_parser(value_parser!(PathBuf)),
                ),
        )
        .subcommand(
            Command::new("fetch")
                .about("Fetch data from the origin")
                .arg(
                    arg!(config: -c --config <FILE> "optional path to the configuration file")
                        .value_parser(value_parser!(PathBuf)),
                ),
        );

    command.get_matches()
}