feat(cli): add --force option to update-channels

This commit is contained in:
alexandre pasmantier 2025-07-13 13:28:01 +02:00
parent 16d7de7d09
commit 99b5c5ce78
3 changed files with 9 additions and 5 deletions

View File

@ -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)]

View File

@ -120,7 +120,7 @@ fn get_default_prototypes_from_repo() -> Result<Vec<DownloadedPrototype>> {
.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(),

View File

@ -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);
}
}