Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Tidy up xtask
Piotr Osiewiczd3a333b8733a
diff --git a/Cargo.lock b/Cargo.lockindex 4df64bfac7c..3f6ebf306fa 100644--- a/Cargo.lock+++ b/Cargo.lock@@ -1150,7 +1150,7 @@ checksum = "4ea181bf566f71cb9a5d17a59e1871af638180a18fb0035c92ae62b705207123"dependencies = ["atty","bitflags",- "clap_derive",+ "clap_derive 3.2.25","clap_lex 0.2.4","indexmap","once_cell",@@ -1166,6 +1166,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "2686c4115cb0810d9a984776e197823d08ec94f176549a89a9efded477c456dc"dependencies = ["clap_builder",+ "clap_derive 4.3.2",+ "once_cell",][[package]]@@ -1194,6 +1196,18 @@ dependencies = ["syn 1.0.109",]+[[package]]+name = "clap_derive"+version = "4.3.2"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "b8cd2b2a819ad6eec39e8f1d6b53001af1e5469f8c177579cdaeb313115b825f"+dependencies = [+ "heck 0.4.1",+ "proc-macro2",+ "quote",+ "syn 2.0.18",+]+[[package]]name = "clap_lex"version = "0.2.4"@@ -8843,6 +8857,7 @@ checksum = "ec7a2a501ed189703dba8b08142f057e887dfc4b2cc4db2d343ac6376ba3e0b9"name = "xtask"version = "0.1.0"dependencies = [+ "anyhow","clap 4.3.5","schemars","serde_json",diff --git a/crates/xtask/Cargo.toml b/crates/xtask/Cargo.tomlindex 2f4ba75ca78..3d3f7d43574 100644--- a/crates/xtask/Cargo.toml+++ b/crates/xtask/Cargo.toml@@ -6,7 +6,8 @@ publish = false# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html[dependencies]-clap = "4.0"+anyhow = "1.0"+clap = {version = "4.0", features = ["derive"]}theme = {path = "../theme"}serde_json.workspace = trueschemars.workspace = truediff --git a/crates/xtask/src/cli.rs b/crates/xtask/src/cli.rsindex e69de29bb2d..bffda1bc167 100644--- a/crates/xtask/src/cli.rs+++ b/crates/xtask/src/cli.rs@@ -0,0 +1,23 @@+use clap::{Parser, Subcommand};+use std::path::PathBuf;+/// Common utilities for Zed developers.+// For more information, see [matklad's repository README](https://github.com/matklad/cargo-xtask/)+#[derive(Parser)]+#[command(author, version, about, long_about = None)]+#[command(propagate_version = true)]+pub struct Cli {+ #[command(subcommand)]+ pub command: Commands,+}++/// Command to run.+#[derive(Subcommand)]+pub enum Commands {+ /// Builds theme types for interop with Typescript.+ BuildThemeTypes {+ #[clap(short, long, default_value = "schemas")]+ out_dir: PathBuf,+ #[clap(short, long, default_value = "theme.json")]+ file_name: PathBuf,+ },+}diff --git a/crates/xtask/src/main.rs b/crates/xtask/src/main.rsindex 03e342fa4a8..881a65fd389 100644--- a/crates/xtask/src/main.rs+++ b/crates/xtask/src/main.rs@@ -1,11 +1,29 @@mod cli;-use schemars::schema_for;+use std::path::PathBuf;+use anyhow::Result;+use clap::Parser;+use schemars::schema_for;use theme::Theme;-fn main() {++fn build_themes(mut out_dir: PathBuf, file_name: PathBuf) -> Result<()> {let theme = schema_for!(Theme);- let output = serde_json::to_string_pretty(&theme).unwrap();- std::fs::create_dir("schemas").ok();- std::fs::write("schemas/theme.json", output).ok();+ let output = serde_json::to_string_pretty(&theme)?;++ std::fs::create_dir(&out_dir)?;++ let mut file_path = out_dir;+ out_dir.push(file_name);++ std::fs::write(file_path, output)?;++ Ok(())+}++fn main() -> Result<()> {+ let args = cli::Cli::parse();+ match args.command {+ cli::Commands::BuildThemeTypes { out_dir, file_name } => build_themes(out_dir, file_name),+ }}