summaryrefslogtreecommitdiffstats
path: root/src/cli.rs
blob: 1049b6438ab088cd229b9545ef4eaa7db8a9c0f7 (plain) (blame)
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
use cmd;

const _DUMMY_DEPENDENCY: &'static str = include_str!("../Cargo.toml");

enum Command {
    Sync(cmd::sync::Options),
    SQL(cmd::sql::Options),
}

pub fn run() -> failure::Fallible<()> {
    match get_options()? {
        Command::Sync(options) => cmd::sync::run(&options),
        Command::SQL(options) => cmd::sql::run(&options),
    }
}

fn get_options() -> failure::Fallible<Command> {
    let matches = app_from_crate!()
        .subcommand(cmd::sync::subcommand())
        .subcommand(cmd::sql::subcommand())
        .get_matches();

    let command = match matches.subcommand() {
        ("sync", Some(matches)) => Command::Sync(cmd::sync::options(matches)),
        ("sql", Some(matches)) => Command::SQL(cmd::sql::options(matches)),

        (name, Some(_)) => bail!("unknown subcommand: {}", name),
        (_, None) => bail!("no subcommand given"),
    };

    Ok(command)
}