Skip to content

Commit

Permalink
prompt name if missing
Browse files Browse the repository at this point in the history
  • Loading branch information
TBS1996 committed Apr 21, 2024
1 parent 40602f4 commit ea7d697
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 10 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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` |
Expand Down
15 changes: 11 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,
#[arg(
short,
Expand Down Expand Up @@ -119,9 +119,8 @@ impl From<Args> 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,
Expand Down Expand Up @@ -162,7 +161,7 @@ enum Action {
},
Add {
url: String,
name: String,
name: Option<String>,
catch_up: bool,
},
Search {
Expand Down Expand Up @@ -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) {
Expand Down
24 changes: 18 additions & 6 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,22 @@ pub fn replacer(val: Value, input: &str) -> String {
output
}

pub fn get_input(prompt: Option<&str>) -> Option<String> {
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![];
Expand All @@ -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(" ") {
Expand Down

0 comments on commit ea7d697

Please sign in to comment.