Skip to content

Commit

Permalink
Add ability to warn on missing theme values (#3705)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
maxdeviant authored Dec 18, 2023
1 parent 734bbfa commit 912f7e6
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 6 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/theme_importer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
31 changes: 25 additions & 6 deletions crates/theme_importer/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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");
Expand Down
2 changes: 2 additions & 0 deletions crates/theme_importer/src/theme_printer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down

0 comments on commit 912f7e6

Please sign in to comment.