Improve schema_generator CLI (#25898)

Release Notes:

- N/A
This commit is contained in:
Peter Tripp 2025-03-05 23:59:57 -05:00 committed by GitHub
parent d44ba92363
commit 7a9e0b37ed
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 35 additions and 13 deletions

View File

@ -0,0 +1,12 @@
# Zed Schema Generator
Prints various Zed schemas to stdout.
## Usage
```sh
cargo run -p schema_generator -- --help
cargo run -p schema_generator -- theme
cargo run -p schema_generator -- icon_theme
```

View File

@ -1,26 +1,36 @@
use anyhow::Result; use anyhow::Result;
use clap::Parser; use clap::{Parser, ValueEnum};
use schemars::schema_for; use schemars::schema_for;
use theme::{IconThemeFamilyContent, ThemeFamilyContent}; use theme::{IconThemeFamilyContent, ThemeFamilyContent};
#[derive(Parser, Debug)] #[derive(Parser, Debug)]
struct Args {} pub struct Args {
#[arg(value_enum)]
pub schema_type: SchemaType,
}
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, ValueEnum)]
#[clap(rename_all = "snake_case")]
pub enum SchemaType {
Theme,
IconTheme,
}
fn main() -> Result<()> { fn main() -> Result<()> {
env_logger::init(); env_logger::init();
let _args = Args::parse(); let args = Args::parse();
let theme_family_schema = schema_for!(ThemeFamilyContent); match args.schema_type {
println!("Theme Schema:"); SchemaType::Theme => {
println!("{}", serde_json::to_string_pretty(&theme_family_schema)?); let schema = schema_for!(ThemeFamilyContent);
println!("{}", serde_json::to_string_pretty(&schema)?);
let icon_theme_family_schema = schema_for!(IconThemeFamilyContent); }
println!("Icon Theme Schema:"); SchemaType::IconTheme => {
println!( let schema = schema_for!(IconThemeFamilyContent);
"{}", println!("{}", serde_json::to_string_pretty(&schema)?);
serde_json::to_string_pretty(&icon_theme_family_schema)? }
); }
Ok(()) Ok(())
} }