diff --git a/cargo-espflash/src/error.rs b/cargo-espflash/src/error.rs index 2bcb645d..2e3eb2de 100644 --- a/cargo-espflash/src/error.rs +++ b/cargo-espflash/src/error.rs @@ -60,24 +60,28 @@ pub enum Error { } /// TOML deserialization error +#[cfg(feature = "cli")] #[derive(Debug)] pub struct TomlError { err: toml::de::Error, source: String, } +#[cfg(feature = "cli")] impl TomlError { pub fn new(err: toml::de::Error, source: String) -> Self { Self { err, source } } } +#[cfg(feature = "cli")] impl Display for TomlError { fn fmt(&self, f: &mut Formatter) -> std::fmt::Result { write!(f, "Failed to parse toml") } } +#[cfg(feature = "cli")] impl Diagnostic for TomlError { fn source_code(&self) -> Option<&dyn SourceCode> { Some(&self.source) @@ -92,6 +96,7 @@ impl Diagnostic for TomlError { } // NOTE: no `source` on purpose to prevent duplicating the message +#[cfg(feature = "cli")] impl std::error::Error for TomlError {} /// Unsupported target error diff --git a/espflash/Cargo.toml b/espflash/Cargo.toml index b8077807..35a168fc 100644 --- a/espflash/Cargo.toml +++ b/espflash/Cargo.toml @@ -53,7 +53,7 @@ sha2 = "0.10.8" slip-codec = { version = "0.4.0", optional = true } strum = { version = "0.26.1", features = ["derive"], optional = true } thiserror = "1.0.56" -toml = "0.8.10" +toml = { version = "0.8.10", optional = true } update-informer = { version = "1.1.0", optional = true } xmas-elf = { version = "0.9.1", optional = true } @@ -78,6 +78,7 @@ cli = [ "dep:indicatif", "dep:lazy_static", "dep:parse_int", + "dep:toml", "dep:update-informer", "serialport" ] @@ -86,4 +87,4 @@ cli = [ serialport = ["flashing", "dep:serialport", "dep:slip-codec", "dep:regex", "dep:strum"] # enables flash stubs and stub commands -flashing = ["xmas-elf"] +flashing = ["xmas-elf", "dep:toml"]