From 45cf36e870b273a4e039e4cb57205c38e7aebf4b Mon Sep 17 00:00:00 2001 From: d1y Date: Thu, 8 Feb 2024 05:23:36 +0800 Subject: [PATCH] theme_importer: Add `--output` flag for outputting the theme to a file (#7486) ```bash cargo run -p theme_importer -- dark-plus-syntax-color-theme.json --output output.json ``` Release Notes: - N/A --------- Co-authored-by: Marshall Bowers --- crates/theme_importer/README.md | 4 ++++ crates/theme_importer/src/main.rs | 12 +++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/crates/theme_importer/README.md b/crates/theme_importer/README.md index 156c338b9a..20b7d063ad 100644 --- a/crates/theme_importer/README.md +++ b/crates/theme_importer/README.md @@ -1 +1,5 @@ # Zed Theme Importer + +```sh +cargo run -p theme_importer -- dark-plus-syntax-color-theme.json --output output-theme.json +``` diff --git a/crates/theme_importer/src/main.rs b/crates/theme_importer/src/main.rs index be470e6833..765dd38ea9 100644 --- a/crates/theme_importer/src/main.rs +++ b/crates/theme_importer/src/main.rs @@ -4,6 +4,7 @@ mod util; mod vscode; use std::fs::File; +use std::io::Write; use std::path::PathBuf; use anyhow::{Context, Result}; @@ -75,6 +76,10 @@ struct Args { #[arg(long)] warn_on_missing: bool, + /// The path to write the output to. + #[arg(long, short)] + output: Option, + #[command(subcommand)] command: Option, } @@ -146,7 +151,12 @@ fn main() -> Result<()> { let theme_json = serde_json::to_string_pretty(&theme).unwrap(); - println!("{}", theme_json); + if let Some(output) = args.output { + let mut file = File::create(output)?; + file.write_all(theme_json.as_bytes())?; + } else { + println!("{}", theme_json); + } log::info!("Done!");