Skip to content

Commit

Permalink
Make pretty JSON optional for generate subcommand (rbx_reflector) (
Browse files Browse the repository at this point in the history
…#401)

Co-authored-by: Kenneth Loeffler <[email protected]>
  • Loading branch information
DervexDev and kennethloeffler authored Mar 7, 2024
1 parent 72d583d commit 06b1fad
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion rbx_reflector/src/cli/defaults_place.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
14 changes: 11 additions & 3 deletions rbx_reflector/src/cli/generate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<PathBuf>,
/// 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<PathBuf>,
/// Whether to pretty-print the JSON output. This has no effect on MessagePack.
#[clap(long)]
pub no_pretty: bool,
}

impl GenerateSubcommand {
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 06b1fad

Please sign in to comment.