diff --git a/README.md b/README.md index f2ccccf..7632550 100644 --- a/README.md +++ b/README.md @@ -96,6 +96,7 @@ The way configuration works is that you can set a 'global value' that applies to | name_pattern | Pattern determining the name of episode files | Yes | ✅ | ✅ | `"{pubdate::%Y-%m-%d} {rss::episode::title}"` | | id_pattern | Episode ID for determining if an episode has been downloaded | Yes | ✅ | ✅ | `"{guid}"` | | download_hook | Path to script that will run after an episode is downloaded | No | ✅ | ✅ | `None` | +| partial_path | The path where partially downloaded episodes are stored | No | ✅ | ✅ | `download_path` | | tracker_path | Path to textfile that tracks downloaded episodes | No | ✅ | ✅ | `download_path/.downloaded` | | max_days | Episodes older than this won't be downloaded | No | ✅ | ✅ | `None` | | max_episodes | Only this number of past episodes will be downloaded | No | ✅ | ✅ | `None` | diff --git a/src/main.rs b/src/main.rs index 7572357..edb190c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -48,7 +48,7 @@ struct Args { help = "Configure to skip episodes published prior to current time. Can be combined with filter, add, and import" )] catch_up: bool, - #[arg(short, long, num_args = 2, value_names = &["URL", "NAME"], help = "Add new podcast")] + #[arg(short, long, num_args = 1..=2, value_names = &["URL", "NAME"], help = "Add new podcast")] add: Vec, #[arg( short, @@ -119,9 +119,8 @@ impl From for Action { } if !args.add.is_empty() { - assert_eq!(args.add.len(), 2); let url = args.add[0].to_string(); - let name = args.add[1].to_string(); + let name = args.add.get(1).cloned(); return Self::Add { url, @@ -162,7 +161,7 @@ enum Action { }, Add { url: String, - name: String, + name: Option, catch_up: bool, }, Search { @@ -207,6 +206,14 @@ async fn main() { url, catch_up, } => { + let name = match name { + Some(name) => name, + None => match utils::get_input(Some("enter name of podcast: ")) { + Some(name) => name, + None => return, + }, + }; + let podcast = config::PodcastConfig::new(url); if config::PodcastConfigs::push(name.clone(), podcast) { diff --git a/src/utils.rs b/src/utils.rs index 87f050d..a6a1acc 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -203,6 +203,22 @@ pub fn replacer(val: Value, input: &str) -> String { output } +pub fn get_input(prompt: Option<&str>) -> Option { + if let Some(prompt) = prompt { + eprint!("{}", prompt); + } + + let mut input = String::new(); + io::stdin().read_line(&mut input).unwrap(); + let input = input.trim(); + + if input.is_empty() { + None + } else { + Some(input.to_string()) + } +} + pub async fn search_podcasts(config: &config::GlobalConfig, query: String, catch_up: bool) { let response = search(&query).await; let mut results = vec![]; @@ -229,13 +245,9 @@ pub async fn search_podcasts(config: &config::GlobalConfig, query: String, catch println!("{}", line); } - let mut input = String::new(); - io::stdin().read_line(&mut input).unwrap(); - let input = input.trim(); - - if input.is_empty() { + let Some(input) = get_input(None) else { return; - } + }; let mut indices = vec![]; for input in input.split(" ") {