From 06b1fadadef5882a77487f0a9a8dd23e2b6058c5 Mon Sep 17 00:00:00 2001 From: Dervex <78505208+DervexHero@users.noreply.github.com> Date: Thu, 7 Mar 2024 17:58:55 +0100 Subject: [PATCH] Make pretty JSON optional for `generate` subcommand (`rbx_reflector`) (#401) Co-authored-by: Kenneth Loeffler --- rbx_reflector/src/cli/defaults_place.rs | 2 +- rbx_reflector/src/cli/generate.rs | 14 +++++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/rbx_reflector/src/cli/defaults_place.rs b/rbx_reflector/src/cli/defaults_place.rs index 7e0b7629b..b0ddbe8c5 100644 --- a/rbx_reflector/src/cli/defaults_place.rs +++ b/rbx_reflector/src/cli/defaults_place.rs @@ -25,7 +25,7 @@ static PLUGIN_SOURCE: &str = include_str!("../../plugin.lua"); #[derive(Debug, Parser)] pub struct DefaultsPlaceSubcommand { /// The path of an API dump that came from the dump command. - #[clap(long = "api_dump")] + #[clap(long)] pub api_dump: PathBuf, /// Where to output the place. The extension must be .rbxlx pub output: PathBuf, diff --git a/rbx_reflector/src/cli/generate.rs b/rbx_reflector/src/cli/generate.rs index 4dac57da9..82089cd2d 100644 --- a/rbx_reflector/src/cli/generate.rs +++ b/rbx_reflector/src/cli/generate.rs @@ -27,11 +27,14 @@ use super::{defaults_place::DefaultsPlaceSubcommand, dump::DumpSubcommand}; /// and write it to disk. #[derive(Debug, Parser)] pub struct GenerateSubcommand { - #[clap(long = "patches")] + #[clap(long)] pub patches: Option, /// Where to output the reflection database. The output format is inferred /// from the file path and supports JSON (.json) and MessagePack (.msgpack). pub output: Vec, + /// Whether to pretty-print the JSON output. This has no effect on MessagePack. + #[clap(long)] + pub no_pretty: bool, } impl GenerateSubcommand { @@ -74,8 +77,13 @@ impl GenerateSubcommand { match extension { Some("json") => { - serde_json::to_writer_pretty(&mut file, &database) - .context("Could not serialize reflection database as JSON")?; + let result = if self.no_pretty { + serde_json::to_writer(&mut file, &database) + } else { + serde_json::to_writer_pretty(&mut file, &database) + }; + + result.context("Could not serialize reflection database as JSON")?; } Some("msgpack") => { let buf = rmp_serde::to_vec(&database)