diff options
Diffstat (limited to 'src/command_handler.rs')
| -rw-r--r-- | src/command_handler.rs | 63 | 
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(()) +} | 
