diff options
| -rw-r--r-- | Cargo.toml | 2 | ||||
| -rw-r--r-- | src/actions.rs | 14 | ||||
| -rw-r--r-- | src/main.rs | 20 | 
3 files changed, 29 insertions, 7 deletions
| @@ -1,6 +1,6 @@  [package]  name = "podcast" -version = "0.5.1" +version = "0.5.2"  authors = ["Nathan Jaremko <njaremko@gmail.com>"]  description = "A command line podcast manager"  license = "GPL-3.0" diff --git a/src/actions.rs b/src/actions.rs index e9cf27b..19fc00c 100644 --- a/src/actions.rs +++ b/src/actions.rs @@ -13,6 +13,9 @@ use rss::Channel;  use toml;  pub fn list_episodes(search: &str) { +    let stdout = io::stdout(); +    let mut handle = stdout.lock(); +      let re = Regex::new(&format!("(?i){}", &search)).expect("Failed to parse regex");      let mut path = get_podcast_dir();      path.push(".rss"); @@ -25,7 +28,12 @@ pub fn list_episodes(search: &str) {              let podcast = Podcast::from(channel);              let episodes = podcast.episodes();              for (num, ep) in episodes.iter().enumerate() { -                println!("({}) {}", episodes.len() - num, ep.title().unwrap()); +                write!( +                    &mut handle, +                    "({}) {}\n", +                    episodes.len() - num, +                    ep.title().unwrap() +                );              }              return;          } @@ -98,8 +106,10 @@ pub fn update_rss(state: &mut State) {  }  pub fn list_subscriptions(state: &State) { +    let stdout = io::stdout(); +    let mut handle = stdout.lock();      for podcast in &state.subscriptions() { -        println!("{}", &podcast.title); +        write!(&mut handle, "{}\n", &podcast.title);      }  } diff --git a/src/main.rs b/src/main.rs index fef188e..7f88d32 100644 --- a/src/main.rs +++ b/src/main.rs @@ -20,7 +20,7 @@ use structs::*;  use clap::{App, Arg, SubCommand}; -const VERSION: &str = "0.5.1"; +const VERSION: &str = "0.5.2";  fn main() {      if let Err(err) = create_directories() { @@ -60,11 +60,20 @@ fn main() {                  ),          )          .subcommand( -            SubCommand::with_name("play") +            SubCommand::with_name("list")                  .about("list episodes of podcast")                  .arg(                      Arg::with_name("PODCAST")                          .help("Regex for subscribed podcast") +                        .index(1), +                ), +        ) +        .subcommand( +            SubCommand::with_name("play") +                .about("play an episode") +                .arg( +                    Arg::with_name("PODCAST") +                        .help("Regex for subscribed podcast")                          .required(true)                          .index(1),                  ) @@ -131,8 +140,11 @@ fn main() {                  None => download_all(&state, podcast),              }          } -        Some("ls") => { -            let list_matches = matches.subcommand_matches("ls").unwrap(); +        Some("ls") | Some("list") => { +            let list_matches = matches +                .subcommand_matches("ls") +                .or(matches.subcommand_matches("list")) +                .unwrap();              match list_matches.value_of("PODCAST") {                  Some(regex) => list_episodes(regex),                  None => list_subscriptions(&state), | 
