From bd1e965f936c9fe652bd940c1f12e3327f06a222 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Sat, 10 Nov 2018 00:50:24 -0500 Subject: add sql subcommand for raw queries this was more painful than i think it should have been --- src/cli.rs | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'src/cli.rs') diff --git a/src/cli.rs b/src/cli.rs index 1976d93..c2cae24 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -3,7 +3,11 @@ const _DUMMY_DEPENDENCY: &'static str = include_str!("../Cargo.toml"); pub enum Command { Sync { username: String, - } + }, + SQL { + query: String, + tsv: bool, + }, } pub fn get_options() -> failure::Fallible { @@ -17,6 +21,20 @@ pub fn get_options() -> failure::Fallible { .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") + ) + ) .get_matches(); let command = match matches.subcommand() { @@ -25,6 +43,12 @@ pub fn get_options() -> failure::Fallible { 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"), + } + }, (name, Some(_)) => bail!("unknown subcommand: {}", name), (_, None) => bail!("no subcommand given"), }; -- cgit v1.2.3-54-g00ecf