summaryrefslogtreecommitdiffstats
path: root/src/cmd
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2018-11-10 02:42:17 -0500
committerJesse Luehrs <doy@tozt.net>2018-11-10 02:42:17 -0500
commitef7cd5bc677c6aabf5517e74ab64eb84d4784057 (patch)
treea176623ad0a80804e1d4f6b714b202e5defa1fb0 /src/cmd
parent07f8d93eff3fd186b7c9bc5125e00cef16bd1a42 (diff)
downloadlastfm-query-ef7cd5bc677c6aabf5517e74ab64eb84d4784057.tar.gz
lastfm-query-ef7cd5bc677c6aabf5517e74ab64eb84d4784057.zip
unify cli and cmd
Diffstat (limited to 'src/cmd')
-rw-r--r--src/cmd/mod.rs27
-rw-r--r--src/cmd/sql.rs3
-rw-r--r--src/cmd/sync.rs3
3 files changed, 29 insertions, 4 deletions
diff --git a/src/cmd/mod.rs b/src/cmd/mod.rs
index a25e955..89c9f5b 100644
--- a/src/cmd/mod.rs
+++ b/src/cmd/mod.rs
@@ -1,2 +1,29 @@
pub mod sql;
pub mod sync;
+
+const _DUMMY_DEPENDENCY: &'static str = include_str!("../../Cargo.toml");
+
+pub trait Command {
+ fn run(&self) -> failure::Fallible<()>;
+}
+
+pub fn run() -> failure::Fallible<()> {
+ get_command()?.run()
+}
+
+fn get_command() -> failure::Fallible<Box<Command>> {
+ let matches = app_from_crate!()
+ .subcommand(sync::subcommand())
+ .subcommand(sql::subcommand())
+ .get_matches();
+
+ let command: Box<Command> = match matches.subcommand() {
+ ("sync", Some(matches)) => Box::new(sync::Command::new(matches)),
+ ("sql", Some(matches)) => Box::new(sql::Command::new(matches)),
+
+ (name, Some(_)) => bail!("unknown subcommand: {}", name),
+ (_, None) => bail!("no subcommand given"),
+ };
+
+ Ok(command)
+}
diff --git a/src/cmd/sql.rs b/src/cmd/sql.rs
index f0dd4b0..d31f326 100644
--- a/src/cmd/sql.rs
+++ b/src/cmd/sql.rs
@@ -1,4 +1,3 @@
-use cli;
use db;
use paths;
@@ -33,7 +32,7 @@ impl Command {
}
}
-impl cli::Command for Command {
+impl super::Command for Command {
fn run(&self) -> failure::Fallible<()> {
let db = db::DB::new(&paths::db_path()?)?;
diff --git a/src/cmd/sync.rs b/src/cmd/sync.rs
index 3dc7ba8..5b71954 100644
--- a/src/cmd/sync.rs
+++ b/src/cmd/sync.rs
@@ -1,4 +1,3 @@
-use cli;
use db;
use lastfm;
use paths;
@@ -27,7 +26,7 @@ impl Command {
}
}
-impl cli::Command for Command {
+impl super::Command for Command {
fn run(&self) -> failure::Fallible<()> {
let db = db::DB::new(&paths::db_path()?)?;
let lastfm = lastfm::LastFMClient::new(&self.username)?;