summaryrefslogtreecommitdiffstats
path: root/src/cmd/mod.rs
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/mod.rs
parent07f8d93eff3fd186b7c9bc5125e00cef16bd1a42 (diff)
downloadlastfm-query-ef7cd5bc677c6aabf5517e74ab64eb84d4784057.tar.gz
lastfm-query-ef7cd5bc677c6aabf5517e74ab64eb84d4784057.zip
unify cli and cmd
Diffstat (limited to 'src/cmd/mod.rs')
-rw-r--r--src/cmd/mod.rs27
1 files changed, 27 insertions, 0 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)
+}