summaryrefslogtreecommitdiffstats
path: root/src/cli.rs
blob: 1976d93b843ea5acaaee03bb6b2300504670fb75 (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
33
const _DUMMY_DEPENDENCY: &'static str = include_str!("../Cargo.toml");

pub enum Command {
    Sync {
        username: String,
    }
}

pub fn get_options() -> failure::Fallible<Command> {
    let matches = app_from_crate!()
        .subcommand(
            clap::SubCommand::with_name("sync")
                .about("Updates the local copy of track data from last.fm")
                .arg(
                    clap::Arg::with_name("username")
                        .required(true)
                        .help("last.fm username to fetch tracks for")
                )
        )
        .get_matches();

    let command = match matches.subcommand() {
        ("sync", Some(matches)) => {
            Command::Sync {
                username: matches.value_of("username").unwrap().to_string(),
            }
        },
        (name, Some(_)) => bail!("unknown subcommand: {}", name),
        (_, None) => bail!("no subcommand given"),
    };

    Ok(command)
}