mirror of
https://github.com/zed-industries/zed.git
synced 2025-01-24 19:10:24 +00:00
theme_importer: Add ability to print theme JSON schema (#7129)
This PR adds a quick subcommand to the `theme_importer` to facilitate printing out the JSON schema for a theme. Note that you do need to pass a `<PATH>` to the subcommand still, even though it will be ignored. I'll rework the CLI to this at some point. The JSON schema for the current version of the theme can also be found at [`https://zed.dev/schema/themes/v0.1.0.json`](https://zed.dev/schema/themes/v0.1.0.json). Release Notes: - N/A
This commit is contained in:
parent
9459394ea0
commit
e5fe811d7a
3 changed files with 29 additions and 2 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -8207,6 +8207,7 @@ dependencies = [
|
||||||
"palette",
|
"palette",
|
||||||
"pathfinder_color",
|
"pathfinder_color",
|
||||||
"rust-embed",
|
"rust-embed",
|
||||||
|
"schemars",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
"simplelog",
|
"simplelog",
|
||||||
|
|
|
@ -18,6 +18,7 @@ log.workspace = true
|
||||||
palette = { version = "0.7.3", default-features = false, features = ["std"] }
|
palette = { version = "0.7.3", default-features = false, features = ["std"] }
|
||||||
pathfinder_color = "0.5"
|
pathfinder_color = "0.5"
|
||||||
rust-embed.workspace = true
|
rust-embed.workspace = true
|
||||||
|
schemars = { workspace = true, features = ["indexmap"] }
|
||||||
serde.workspace = true
|
serde.workspace = true
|
||||||
serde_json.workspace = true
|
serde_json.workspace = true
|
||||||
simplelog = "0.9"
|
simplelog = "0.9"
|
||||||
|
|
|
@ -7,13 +7,14 @@ use std::fs::File;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use anyhow::{Context, Result};
|
use anyhow::{Context, Result};
|
||||||
use clap::Parser;
|
use clap::{Parser, Subcommand};
|
||||||
use indexmap::IndexMap;
|
use indexmap::IndexMap;
|
||||||
use json_comments::StripComments;
|
use json_comments::StripComments;
|
||||||
use log::LevelFilter;
|
use log::LevelFilter;
|
||||||
|
use schemars::schema_for;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use simplelog::{TermLogger, TerminalMode};
|
use simplelog::{TermLogger, TerminalMode};
|
||||||
use theme::{Appearance, AppearanceContent};
|
use theme::{Appearance, AppearanceContent, ThemeFamilyContent};
|
||||||
|
|
||||||
use crate::vscode::VsCodeTheme;
|
use crate::vscode::VsCodeTheme;
|
||||||
use crate::vscode::VsCodeThemeConverter;
|
use crate::vscode::VsCodeThemeConverter;
|
||||||
|
@ -74,6 +75,15 @@ struct Args {
|
||||||
/// Whether to warn when values are missing from the theme.
|
/// Whether to warn when values are missing from the theme.
|
||||||
#[arg(long)]
|
#[arg(long)]
|
||||||
warn_on_missing: bool,
|
warn_on_missing: bool,
|
||||||
|
|
||||||
|
#[command(subcommand)]
|
||||||
|
command: Option<Command>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Subcommand)]
|
||||||
|
enum Command {
|
||||||
|
/// Prints the JSON schema for a theme.
|
||||||
|
PrintSchema,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() -> Result<()> {
|
fn main() -> Result<()> {
|
||||||
|
@ -97,6 +107,21 @@ fn main() -> Result<()> {
|
||||||
TermLogger::init(LevelFilter::Trace, log_config, TerminalMode::Mixed)
|
TermLogger::init(LevelFilter::Trace, log_config, TerminalMode::Mixed)
|
||||||
.expect("could not initialize logger");
|
.expect("could not initialize logger");
|
||||||
|
|
||||||
|
if let Some(command) = args.command {
|
||||||
|
match command {
|
||||||
|
Command::PrintSchema => {
|
||||||
|
let theme_family_schema = schema_for!(ThemeFamilyContent);
|
||||||
|
|
||||||
|
println!(
|
||||||
|
"{}",
|
||||||
|
serde_json::to_string_pretty(&theme_family_schema).unwrap()
|
||||||
|
);
|
||||||
|
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let theme_file_path = args.theme_path;
|
let theme_file_path = args.theme_path;
|
||||||
|
|
||||||
let theme_file = match File::open(&theme_file_path) {
|
let theme_file = match File::open(&theme_file_path) {
|
||||||
|
|
Loading…
Reference in a new issue