Skip to content

Commit fe67521

Browse files
committed
refactor(cli)!: deprecate json flags in favor of json-summary
1 parent f02d7e7 commit fe67521

File tree

1 file changed

+26
-7
lines changed

1 file changed

+26
-7
lines changed

crates/cli/src/main.rs

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,12 @@ struct Generate {
129129
/// Produce a report of the states for the given rule, use `-` to report every rule
130130
#[arg(long)]
131131
pub report_states_for_rule: Option<String>,
132-
/// Report conflicts in a JSON format
133-
#[arg(long)]
132+
/// Deprecated: use --json-summary
133+
#[arg(long, conflicts_with = "json_summary")]
134134
pub json: bool,
135+
/// Report conflicts in a JSON format
136+
#[arg(long, conflicts_with = "json")]
137+
pub json_summary: bool,
135138
/// The name or path of the JavaScript runtime to use for generating parsers
136139
#[cfg(not(feature = "qjs-rt"))]
137140
#[arg(
@@ -249,9 +252,12 @@ struct Parse {
249252
/// Open `log.html` in the default browser, if `--debug-graph` is supplied
250253
#[arg(long)]
251254
pub open_log: bool,
252-
/// Output parsing results in a JSON format
253-
#[arg(long, short = 'j')]
255+
/// Deprecated: use --json-summary
256+
#[arg(long, short = 'j', conflicts_with = "json_summary")]
254257
pub json: bool,
258+
/// Output parsing results in a JSON format
259+
#[arg(long, conflicts_with = "json")]
260+
pub json_summary: bool,
255261
/// The path to an alternative config.json file
256262
#[arg(long)]
257263
pub config_path: Option<PathBuf>,
@@ -855,6 +861,13 @@ impl Generate {
855861
}
856862
});
857863

864+
let json_summary = if self.json {
865+
warn!("--json is deprecated, use --json-summary instead");
866+
true
867+
} else {
868+
self.json_summary
869+
};
870+
858871
if let Err(err) = tree_sitter_generate::generate_parser_in_directory(
859872
current_dir,
860873
self.output.as_deref(),
@@ -869,7 +882,7 @@ impl Generate {
869882
OptLevel::default()
870883
},
871884
) {
872-
if self.json {
885+
if json_summary {
873886
eprintln!("{}", serde_json::to_string_pretty(&err)?);
874887
// Exit early to prevent errors from being printed a second time in the caller
875888
std::process::exit(1);
@@ -940,13 +953,19 @@ impl Parse {
940953
fn run(self, mut loader: loader::Loader, current_dir: &Path) -> Result<()> {
941954
let config = Config::load(self.config_path)?;
942955
let color = env::var("NO_COLOR").map_or(true, |v| v != "1");
956+
let json_summary = if self.json {
957+
warn!("--json is deprecated, use --json-summary instead");
958+
true
959+
} else {
960+
self.json_summary
961+
};
943962
let output = if self.output_dot {
944963
ParseOutput::Dot
945964
} else if self.output_xml {
946965
ParseOutput::Xml
947966
} else if self.output_cst {
948967
ParseOutput::Cst
949-
} else if self.quiet || self.json {
968+
} else if self.quiet || json_summary {
950969
ParseOutput::Quiet
951970
} else {
952971
ParseOutput::Normal
@@ -1142,7 +1161,7 @@ impl Parse {
11421161
if should_track_stats {
11431162
println!("\n{}", stats.cumulative_stats);
11441163
}
1145-
if self.json {
1164+
if json_summary {
11461165
println!("{}", serde_json::to_string_pretty(&stats)?);
11471166
}
11481167

0 commit comments

Comments
 (0)