aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNathan Jaremko2018-03-22 00:10:33 -0400
committerNathan Jaremko2018-03-22 00:10:33 -0400
commit829f9fca259034d1a63173bb19e43b1c24c3face (patch)
tree8b59381393f1e41b994afe9a4b25af9ed0309629
parent7a110aa9098c5fa2c772dd5f4dcc93ef3322de00 (diff)
downloadpodcast-829f9fca259034d1a63173bb19e43b1c24c3face.tar.bz2
Fix ls/list to allow piping
-rw-r--r--Cargo.toml2
-rw-r--r--src/actions.rs14
-rw-r--r--src/main.rs20
3 files changed, 29 insertions, 7 deletions
diff --git a/Cargo.toml b/Cargo.toml
index cedc079..783ffa5 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -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),