Skip to content

Commit 195f461

Browse files
committed
Add modules containing helper functions for initializing the logger and checking for updates
1 parent c35fad9 commit 195f461

File tree

5 files changed

+61
-127
lines changed

5 files changed

+61
-127
lines changed

Cargo.lock

Lines changed: 23 additions & 105 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cargo-espflash/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ pkg-fmt = "zip"
3333
cargo_metadata = "0.15.0"
3434
cargo_toml = "0.11.6"
3535
clap = { version = "3.2.22", features = ["derive", "env"] }
36+
env_logger = "0.9.0"
3637
espflash = { version = "=1.7.1-dev", path = "../espflash" }
3738
log = "0.4.17"
3839
miette = { version = "5.3.0", features = ["fancy"] }
3940
serde = { version = "1.0.144", features = ["derive"] }
4041
strum = "0.24.1"
4142
thiserror = "1.0.35"
42-
tracing-subscriber = { version = "0.3.15", features = [ "env-filter" ] }
4343
toml = "0.5.9"

espflash/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ csv = "1.1.6"
3939
dialoguer = "0.10.2"
4040
directories-next = "2.0.0"
4141
espmonitor = "0.10.0"
42+
env_logger = "0.9.0"
4243
flate2 = "1.0.24"
4344
indicatif = "0.17.1"
4445
log = "0.4.17"
@@ -52,7 +53,6 @@ serde-hex = "0.1.0"
5253
serde_json = "1.0.85"
5354
serde_plain = "1.0.0"
5455
serialport = "4.2.0"
55-
tracing-subscriber = { version = "0.3.15", features = [ "env-filter" ] }
5656
sha2 = "0.10.6"
5757
slip-codec = "0.3.3"
5858
strum = "0.24.1"

espflash/src/cli/mod.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -418,13 +418,3 @@ pub fn write_bin_to_flash(opts: WriteBinToFlashOpts) -> Result<()> {
418418

419419
Ok(())
420420
}
421-
422-
pub fn check_for_updates(name: &str, version: &str) {
423-
const NO_INTERVAL: Duration = Duration::from_secs(0);
424-
425-
let informer = update_informer::new(registry::Crates, name, version).interval(NO_INTERVAL);
426-
427-
if let Some(version) = informer.check_version().ok().flatten() {
428-
println!("New version of {name} is available: {version}\n");
429-
}
430-
}

espflash/src/lib.rs

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
1-
pub use chip::Chip;
2-
pub use cli::config::Config;
3-
pub use elf::{FlashFrequency, FlashMode};
4-
pub use error::{Error, InvalidPartitionTable, MissingPartitionTable};
5-
pub use flasher::{FlashSize, Flasher};
6-
pub use image_format::ImageFormatId;
7-
pub use partition_table::PartitionTable;
1+
pub use self::{
2+
chip::Chip,
3+
cli::config::Config,
4+
elf::{FlashFrequency, FlashMode},
5+
error::{Error, InvalidPartitionTable, MissingPartitionTable},
6+
flasher::{FlashSize, Flasher},
7+
image_format::ImageFormatId,
8+
partition_table::PartitionTable,
9+
};
810

911
pub mod chip;
12+
pub mod cli;
1013
pub mod command;
1114
pub mod connection;
1215
pub mod elf;
@@ -16,8 +19,31 @@ pub mod flash_target;
1619
pub mod flasher;
1720
pub mod image_format;
1821
pub mod partition_table;
22+
pub mod stubs;
1923

20-
#[doc(hidden)]
21-
pub mod cli;
24+
pub mod logging {
25+
use env_logger::Env;
26+
use log::LevelFilter;
2227

23-
pub mod stubs;
28+
pub fn initialize_logger(filter: LevelFilter) {
29+
env_logger::Builder::from_env(Env::default().default_filter_or(filter.as_str())).init();
30+
}
31+
}
32+
33+
pub mod update {
34+
use std::time::Duration;
35+
36+
use log::info;
37+
use update_informer::{registry, Check};
38+
39+
pub fn check_for_update(name: &str, version: &str) {
40+
// By setting the interval to 0 seconds we invalidate the cache with each
41+
// invocation and ensure we're getting up-to-date results
42+
let informer =
43+
update_informer::new(registry::Crates, name, version).interval(Duration::from_secs(0));
44+
45+
if let Some(version) = informer.check_version().ok().flatten() {
46+
info!("🚀 A new version of {name} is available: {version}");
47+
}
48+
}
49+
}

0 commit comments

Comments
 (0)