summaryrefslogtreecommitdiffstats
path: root/src/cli.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/cli.rs')
-rw-r--r--src/cli.rs55
1 files changed, 10 insertions, 45 deletions
diff --git a/src/cli.rs b/src/cli.rs
index 4b6aa0d..1049b64 100644
--- a/src/cli.rs
+++ b/src/cli.rs
@@ -3,62 +3,27 @@ use cmd;
const _DUMMY_DEPENDENCY: &'static str = include_str!("../Cargo.toml");
enum Command {
- Sync {
- username: String,
- },
- SQL {
- query: String,
- tsv: bool,
- },
+ Sync(cmd::sync::Options),
+ SQL(cmd::sql::Options),
}
pub fn run() -> failure::Fallible<()> {
- let command = get_options()?;
- match command {
- Command::Sync { username } => cmd::sync::run(&username),
- Command::SQL { query, tsv } => cmd::sql::run(&query, tsv),
+ 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(
- 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")
- )
- )
- .subcommand(
- clap::SubCommand::with_name("sql")
- .about("Run a query against the local database")
- .arg(
- clap::Arg::with_name("query")
- .required(true)
- .help("query to run")
- )
- .arg(
- clap::Arg::with_name("tsv")
- .long("tsv")
- .help("format output as tsv")
- )
- )
+ .subcommand(cmd::sync::subcommand())
+ .subcommand(cmd::sql::subcommand())
.get_matches();
let command = match matches.subcommand() {
- ("sync", Some(matches)) => {
- Command::Sync {
- username: matches.value_of("username").unwrap().to_string(),
- }
- },
- ("sql", Some(matches)) => {
- Command::SQL {
- query: matches.value_of("query").unwrap().to_string(),
- tsv: matches.is_present("tsv"),
- }
- },
+ ("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"),
};