summaryrefslogtreecommitdiffstats
path: root/src/cmd
diff options
context:
space:
mode:
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)?;