Add ability to warn on missing theme values (#3705)

Marshall Bowers created

This PR adds the ability to warn in the `theme_importer` when a theme is
missing values.

Providing the `--warn-on-missing` flag to the `theme_importer` will
print a warning for missing theme value when printing the theme.

```sh
cargo run -p theme_importer -- --warn-on-missing
```

Release Notes:

- N/A

Change summary

Cargo.lock                                 |  1 
crates/theme_importer/Cargo.toml           |  1 
crates/theme_importer/src/main.rs          | 31 +++++++++++++++++++----
crates/theme_importer/src/theme_printer.rs |  2 +
4 files changed, 29 insertions(+), 6 deletions(-)

Detailed changes

Cargo.lock 🔗

@@ -9813,6 +9813,7 @@ name = "theme_importer"
 version = "0.1.0"
 dependencies = [
  "anyhow",
+ "clap 4.4.4",
  "convert_case 0.6.0",
  "gpui2",
  "indexmap 1.9.3",

crates/theme_importer/Cargo.toml 🔗

@@ -8,6 +8,7 @@ publish = false
 
 [dependencies]
 anyhow.workspace = true
+clap = { version = "4.4", features = ["derive"] }
 convert_case = "0.6.0"
 gpui = { package = "gpui2", path = "../gpui2" }
 indexmap = { version = "1.6.2", features = ["serde"] }

crates/theme_importer/src/main.rs 🔗

@@ -10,6 +10,7 @@ use std::process::Command;
 use std::str::FromStr;
 
 use anyhow::{anyhow, Context, Result};
+use clap::Parser;
 use convert_case::{Case, Casing};
 use gpui::serde_json;
 use indexmap::IndexMap;
@@ -61,16 +62,34 @@ pub struct ThemeMetadata {
     pub appearance: ThemeAppearanceJson,
 }
 
+#[derive(Parser)]
+#[command(author, version, about, long_about = None)]
+struct Args {
+    /// Whether to warn when values are missing from the theme.
+    #[arg(long)]
+    warn_on_missing: bool,
+}
+
 fn main() -> Result<()> {
     const SOURCE_PATH: &str = "assets/themes/src/vscode";
     const OUT_PATH: &str = "crates/theme2/src/themes";
 
-    let log_config = simplelog::ConfigBuilder::new()
-        .set_level_color(log::Level::Trace, simplelog::Color::Cyan)
-        .set_level_color(log::Level::Info, simplelog::Color::Blue)
-        .set_level_color(log::Level::Warn, simplelog::Color::Yellow)
-        .set_level_color(log::Level::Error, simplelog::Color::Red)
-        .build();
+    let args = Args::parse();
+
+    let log_config = {
+        let mut config = simplelog::ConfigBuilder::new();
+        config
+            .set_level_color(log::Level::Trace, simplelog::Color::Cyan)
+            .set_level_color(log::Level::Info, simplelog::Color::Blue)
+            .set_level_color(log::Level::Warn, simplelog::Color::Yellow)
+            .set_level_color(log::Level::Error, simplelog::Color::Red);
+
+        if !args.warn_on_missing {
+            config.add_filter_ignore_str("theme_printer");
+        }
+
+        config.build()
+    };
 
     TermLogger::init(LevelFilter::Trace, log_config, TerminalMode::Mixed)
         .expect("could not initialize logger");

crates/theme_importer/src/theme_printer.rs 🔗

@@ -282,6 +282,8 @@ impl<'a> Debug for ThemeColorsRefinementPrinter<'a> {
                 HslaPrinter(color).fmt(f)?;
                 f.write_str(")")?;
                 f.write_str(",")?;
+            } else {
+                log::warn!(target: "theme_printer", "No value for '{}' in theme", color_name);
             }
         }