Skip to content

Commit

Permalink
Add skip update check option (#689)
Browse files Browse the repository at this point in the history
* Add skip update check option

* Add doc comments for `skip_update_check`

---------

Co-authored-by: David Amiot <david.amiot@thalesgroup.com>
Co-authored-by: Jesse Braham <jesse@beta7.io>
  • Loading branch information
3 people authored Oct 18, 2024
1 parent 7b0c6ac commit 726f495
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
16 changes: 13 additions & 3 deletions cargo-espflash/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
}

Expand Down Expand Up @@ -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()?;
Expand Down
13 changes: 10 additions & 3 deletions espflash/src/bin/espflash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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()?;
Expand Down

0 comments on commit 726f495

Please sign in to comment.