From 726f495ee6fe191e37bb4ff694c18ff4e4efa659 Mon Sep 17 00:00:00 2001 From: Thraen <10695842+Thrathra@users.noreply.github.com> Date: Fri, 18 Oct 2024 10:56:29 +0200 Subject: [PATCH] Add skip update check option (#689) * Add skip update check option * Add doc comments for `skip_update_check` --------- Co-authored-by: David Amiot Co-authored-by: Jesse Braham --- CHANGELOG.md | 1 + cargo-espflash/src/main.rs | 16 +++++++++++++--- espflash/src/bin/espflash.rs | 13 ++++++++++--- 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 638705f0..7445994f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Fixed `partition-table-offset` argument to accept offsets in hexadecimal (#682) - espflash defmt log didn't display timestamp, according to [defmt doc](https://defmt.ferrous-systems.com/timestamps). (#680) - Fixed pattern matching to detect download mode over multiple lines (#685) +- Add an option to prevent update checks (#689) ### Changed diff --git a/cargo-espflash/src/main.rs b/cargo-espflash/src/main.rs index f01d1710..26bc3aa2 100644 --- a/cargo-espflash/src/main.rs +++ b/cargo-espflash/src/main.rs @@ -51,6 +51,10 @@ enum CargoSubcommand { Espflash { #[clap(subcommand)] subcommand: Commands, + + /// Do not check for updates + #[clap(short, long, global = true, action)] + skip_update_check: bool, }, } @@ -203,13 +207,19 @@ fn main() -> Result<()> { // Attempt to parse any provided comand-line arguments, or print the help // message and terminate if the invocation is not correct. - let CargoSubcommand::Espflash { subcommand: args } = Cli::parse().subcommand; - debug!("{:#?}", args); + let cli = Cli::parse(); + let CargoSubcommand::Espflash { + subcommand: args, + skip_update_check, + } = cli.subcommand; + debug!("{:#?}, {:#?}", args, skip_update_check); // Only check for updates once the command-line arguments have been processed, // to avoid printing any update notifications when the help message is // displayed. - check_for_update(env!("CARGO_PKG_NAME"), env!("CARGO_PKG_VERSION")); + if !skip_update_check { + check_for_update(env!("CARGO_PKG_NAME"), env!("CARGO_PKG_VERSION")); + } // Load any user configuration, if present. let config = Config::load()?; diff --git a/espflash/src/bin/espflash.rs b/espflash/src/bin/espflash.rs index b535bf05..6dd80a5e 100644 --- a/espflash/src/bin/espflash.rs +++ b/espflash/src/bin/espflash.rs @@ -28,6 +28,10 @@ use miette::{IntoDiagnostic, Result, WrapErr}; pub struct Cli { #[command(subcommand)] subcommand: Commands, + + /// Do not check for updates + #[clap(short, long, global = true, action)] + skip_update_check: bool, } #[derive(Debug, Subcommand)] @@ -158,13 +162,16 @@ fn main() -> Result<()> { // Attempt to parse any provided comand-line arguments, or print the help // message and terminate if the invocation is not correct. - let args = Cli::parse().subcommand; - debug!("{:#?}", args); + let cli = Cli::parse(); + let args = cli.subcommand; + debug!("{:#?}, {:#?}", args, cli.skip_update_check); // Only check for updates once the command-line arguments have been processed, // to avoid printing any update notifications when the help message is // displayed. - check_for_update(env!("CARGO_PKG_NAME"), env!("CARGO_PKG_VERSION")); + if !cli.skip_update_check { + check_for_update(env!("CARGO_PKG_NAME"), env!("CARGO_PKG_VERSION")); + } // Load any user configuration, if present. let config = Config::load()?;