Skip to content

Commit

Permalink
fix(cable): cable channels now take precedence over builtins for the …
Browse files Browse the repository at this point in the history
…cli / shell integration (#278)

Fixes #275
  • Loading branch information
alexpasmantier authored Jan 14, 2025
1 parent 1934d3f commit c227b2a
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions crates/television/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,17 +178,19 @@ pub enum ParsedCliChannel {

fn parse_channel(channel: &str) -> Result<ParsedCliChannel> {
let cable_channels = cable::load_cable_channels().unwrap_or_default();
CliTvChannel::try_from(channel)
.map(ParsedCliChannel::Builtin)
.or_else(|_| {
cable_channels
.iter()
.find(|(k, _)| k.to_lowercase() == channel)
.map_or_else(
|| Err(eyre!("Unknown channel: {}", channel)),
|(_, v)| Ok(ParsedCliChannel::Cable(v.clone())),
)
})
// try to parse the channel as a cable channel
cable_channels
.iter()
.find(|(k, _)| k.to_lowercase() == channel)
.map_or_else(
|| {
// try to parse the channel as a builtin channel
CliTvChannel::try_from(channel)
.map(ParsedCliChannel::Builtin)
.map_err(|_| eyre!("Unknown channel: {}", channel))
},
|(_, v)| Ok(ParsedCliChannel::Cable(v.clone())),
)
}

pub fn list_cable_channels() -> Vec<String> {
Expand Down

0 comments on commit c227b2a

Please sign in to comment.