From 912f7e6c1a149d62b5f36f50304ff63ed0201840 Mon Sep 17 00:00:00 2001 From: Marshall Bowers Date: Mon, 18 Dec 2023 17:18:49 -0500 Subject: [PATCH] Add ability to warn on missing theme values (#3705) 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 --- 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(-) diff --git a/Cargo.lock b/Cargo.lock index 0a4801524e..cb0d54022f 100644 --- a/Cargo.lock +++ b/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", diff --git a/crates/theme_importer/Cargo.toml b/crates/theme_importer/Cargo.toml index 82ab18d48d..4b8641faa4 100644 --- a/crates/theme_importer/Cargo.toml +++ b/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"] } diff --git a/crates/theme_importer/src/main.rs b/crates/theme_importer/src/main.rs index 0005d932d4..a02b1ca114 100644 --- a/crates/theme_importer/src/main.rs +++ b/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"); diff --git a/crates/theme_importer/src/theme_printer.rs b/crates/theme_importer/src/theme_printer.rs index 4726c90c6d..13123d854f 100644 --- a/crates/theme_importer/src/theme_printer.rs +++ b/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); } }