aboutsummaryrefslogtreecommitdiffstats
path: root/src/command_handler.rs
diff options
context:
space:
mode:
authorNathan Jaremko2019-03-02 20:30:54 -0500
committerNathan Jaremko2019-03-02 20:30:54 -0500
commit9c9fb906cd6c05105d96fa586f429764b12169ca (patch)
tree1499d2e38c368952886fb72a01251be47448603c /src/command_handler.rs
parent2d34d8e812f3e85b0d10f126bf5f334847d0fbca (diff)
downloadpodcast-9c9fb906cd6c05105d96fa586f429764b12169ca.tar.bz2
0.10.0 - Lots of Improvements
Diffstat (limited to 'src/command_handler.rs')
-rw-r--r--src/command_handler.rs63
1 files changed, 63 insertions, 0 deletions
diff --git a/src/command_handler.rs b/src/command_handler.rs
new file mode 100644
index 0000000..742b79e
--- /dev/null
+++ b/src/command_handler.rs
@@ -0,0 +1,63 @@
+use clap::{App, ArgMatches};
+
+use crate::actions::*;
+use crate::arg_parser;
+use crate::commands;
+use crate::errors::*;
+use crate::structs::*;
+
+pub fn parse_sub_command(matches: &ArgMatches) -> commands::Command {
+ match matches.subcommand_name() {
+ Some("download") => commands::Command::Download,
+ Some("ls") | Some("list") => commands::Command::List,
+ Some("play") => commands::Command::Play,
+ Some("sub") | Some("subscribe") => commands::Command::Subscribe,
+ Some("search") => commands::Command::Search,
+ Some("rm") => commands::Command::Remove,
+ Some("completion") => commands::Command::Complete,
+ Some("refresh") => commands::Command::Refresh,
+ Some("update") => commands::Command::Update,
+ _ => commands::Command::NoMatch,
+ }
+}
+
+pub fn handle_matches(
+ version: &str,
+ state: &mut State,
+ config: &Config,
+ app: &mut App,
+ matches: &ArgMatches,
+) -> Result<()> {
+ let command = parse_sub_command(matches);
+ match command {
+ commands::Command::Download => {
+ arg_parser::download(state, matches)?;
+ }
+ commands::Command::List => {
+ arg_parser::list(state, matches)?;
+ }
+ commands::Command::Play => {
+ arg_parser::play(state, matches)?;
+ }
+ commands::Command::Subscribe => {
+ arg_parser::subscribe(state, config, matches)?;
+ }
+ commands::Command::Search => {
+ println!("This feature is coming soon...");
+ }
+ commands::Command::Remove => {
+ arg_parser::remove(state, matches)?;
+ }
+ commands::Command::Complete => {
+ arg_parser::complete(app, matches)?;
+ }
+ commands::Command::Refresh => {
+ update_rss(state);
+ }
+ commands::Command::Update => {
+ check_for_update(version)?;
+ }
+ _ => (),
+ };
+ Ok(())
+}