diff --git a/television/cli/args.rs b/television/cli/args.rs index 7aea5c2..936278b 100644 --- a/television/cli/args.rs +++ b/television/cli/args.rs @@ -482,7 +482,11 @@ pub enum Command { }, /// Downloads the latest collection of default channel prototypes from github /// and saves them to the local configuration directory. - UpdateChannels, + UpdateChannels { + /// Force update on already existing channels. + #[arg(long, default_value = "false")] + force: bool, + }, } #[derive(Debug, Clone, Copy, PartialEq, ValueEnum)] diff --git a/television/gh.rs b/television/gh.rs index 58370e3..7d16419 100644 --- a/television/gh.rs +++ b/television/gh.rs @@ -120,7 +120,7 @@ fn get_default_prototypes_from_repo() -> Result> { .collect()) } -pub fn update_local_channels() -> Result<()> { +pub fn update_local_channels(force: &bool) -> Result<()> { println!("{}", "Fetching latest cable channels...".bold()); let default_prototypes = get_default_prototypes_from_repo()?; println!("{}", "\nSaving channels locally...".bold()); @@ -133,7 +133,7 @@ pub fn update_local_channels() -> Result<()> { let file_path = cable_path.join(&p.name).with_extension(CHANNEL_FILE_FORMAT); // if the file already exists, don't overwrite it - if file_path.exists() { + if file_path.exists() && !force { println!( " Channel {} already exists at {}, SKIPPING...", p.name.blue().bold(), diff --git a/television/main.rs b/television/main.rs index 2190a3d..8c8b23f 100644 --- a/television/main.rs +++ b/television/main.rs @@ -241,8 +241,8 @@ pub fn handle_subcommand(command: &Command, config: &Config) -> Result<()> { println!("{script}"); exit(0); } - Command::UpdateChannels => { - update_local_channels()?; + Command::UpdateChannels { force } => { + update_local_channels(force)?; exit(0); } }