Repository: esp-rs/espflash (language: rust)

Issue:
Add an option to prevent checking for new version
Hi, I'm working behind a proxy and it seems the programs tries to connect to crates.io in order to find updates.
As the requests times out, it takes a lot of time to even scan a board.
Is it possible to add an option to prevent such connections?

Thanks in advance!


Discussion / hints:
Hi! Currently, we don't have any way of preventing this check, but we would happily accept a contribution adding an argument that skips calling https://github.com/esp-rs/espflash/blob/main/espflash/src/bin/espflash.rs#L167 (this should be also duplicated in cargo-espflash)

Fix patch:
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()?;


Test patch: