From 3bc8b6cd82cfdc911acab0e4b636120b6738509a Mon Sep 17 00:00:00 2001 From: Sergei Zharinov Date: Sat, 6 Dec 2025 13:43:43 -0300 Subject: [PATCH] fix: Simplify CLI debug command options and behavior --- AGENTS.md | 10 +++--- crates/plotnik-cli/src/cli.rs | 18 +++-------- crates/plotnik-cli/src/commands/debug/mod.rs | 32 ++++++++------------ crates/plotnik-cli/src/main.rs | 2 -- 4 files changed, 22 insertions(+), 40 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 2433c4f7..eca8d75c 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -66,14 +66,14 @@ Run: `cargo run -p plotnik-cli -- ` Inputs: `-q/--query `, `--query-file `, `--source `, `-s/--source-file `, `-l/--lang ` -Output: `--show-query`, `--show-source`, `--only-symbols`, `--cst`, `--raw`, `--spans`, `--cardinalities` +Output (inferred from input): `--only-symbols`, `--cst`, `--raw`, `--spans`, `--cardinalities` ```sh -cargo run -p plotnik-cli -- debug -q '(identifier) @id' --show-query +cargo run -p plotnik-cli -- debug -q '(identifier) @id' cargo run -p plotnik-cli -- debug -q '(identifier) @id' --only-symbols -cargo run -p plotnik-cli -- debug -s app.ts --show-source -cargo run -p plotnik-cli -- debug -s app.ts --show-source --raw -cargo run -p plotnik-cli -- debug -q '(function_declaration) @fn' -s app.ts -l typescript --show-query +cargo run -p plotnik-cli -- debug -s app.ts +cargo run -p plotnik-cli -- debug -s app.ts --raw +cargo run -p plotnik-cli -- debug -q '(function_declaration) @fn' -s app.ts -l typescript ``` ## Syntax diff --git a/crates/plotnik-cli/src/cli.rs b/crates/plotnik-cli/src/cli.rs index c570577b..395fad1f 100644 --- a/crates/plotnik-cli/src/cli.rs +++ b/crates/plotnik-cli/src/cli.rs @@ -32,11 +32,11 @@ pub struct Cli { pub enum Command { /// Debug and inspect queries and source files #[command(after_help = r#"EXAMPLES: - plotnik debug -q '(identifier) @id' --show-query + plotnik debug -q '(identifier) @id' plotnik debug -q '(identifier) @id' --only-symbols - plotnik debug -s app.ts --show-source - plotnik debug -s app.ts --show-source --raw - plotnik debug -q '(function_declaration) @fn' -s app.ts -l typescript --show-query"#)] + plotnik debug -s app.ts + plotnik debug -s app.ts --raw + plotnik debug -q '(function_declaration) @fn' -s app.ts -l typescript"#)] Debug { #[command(flatten)] query: QueryArgs, @@ -88,19 +88,11 @@ pub struct SourceArgs { #[derive(Args)] pub struct OutputArgs { - /// Show query syntax tree - #[arg(long = "show-query")] - pub query: bool, - /// Colorize output (auto-detected by default) #[arg(long, default_value = "auto", value_name = "WHEN")] pub color: ColorChoice, - /// Show source syntax tree - #[arg(long = "show-source")] - pub source: bool, - - /// Show only symbol table + /// Show only symbol table (instead of query AST) #[arg(long = "only-symbols")] pub symbols: bool, diff --git a/crates/plotnik-cli/src/commands/debug/mod.rs b/crates/plotnik-cli/src/commands/debug/mod.rs index 23603f88..a4e41771 100644 --- a/crates/plotnik-cli/src/commands/debug/mod.rs +++ b/crates/plotnik-cli/src/commands/debug/mod.rs @@ -13,8 +13,6 @@ pub struct DebugArgs { pub source_text: Option, pub source_file: Option, pub lang: Option, - pub query: bool, - pub source: bool, pub symbols: bool, pub raw: bool, pub cst: bool, @@ -45,15 +43,11 @@ pub fn run(args: DebugArgs) { }) }); - let show_headers = [args.query, args.source, args.symbols] - .iter() - .filter(|&&x| x) - .count() - >= 2; + let show_query = has_query_input && !args.symbols; + let show_source = has_source_input; + let show_headers = (show_query || args.symbols) && show_source; - if args.query - && let Some(ref q) = query - { + if show_query && let Some(ref q) = query { if show_headers { println!("=== QUERY ==="); } @@ -83,7 +77,7 @@ pub fn run(args: DebugArgs) { ); } - if args.source { + if show_source { let resolved_lang = resolve_lang(&args.lang, &args.source_text, &args.source_file); let source_code = load_source(&args.source_text, &args.source_file); let tree = parse_tree(&source_code, resolved_lang); @@ -120,20 +114,18 @@ fn load_query(args: &DebugArgs) -> String { } fn validate(args: &DebugArgs, has_query: bool, has_source: bool) -> Result<(), &'static str> { - if (args.query || args.symbols) && !has_query { - return Err("--query and --only-symbols require --query-text or --query-file"); + if !has_query && !has_source { + return Err( + "specify at least one input: -q/--query, --query-file, -s/--source-file, or --source", + ); } - if args.source && !has_source { - return Err("--source requires --source-text or --source-file"); + if args.symbols && !has_query { + return Err("--only-symbols requires -q/--query or --query-file"); } if args.source_text.is_some() && args.lang.is_none() { - return Err("--lang is required when using --source-text"); - } - - if !args.query && !args.source && !args.symbols { - return Err("specify at least one output: --query, --source, or --only-symbols"); + return Err("--lang is required when using --source"); } Ok(()) diff --git a/crates/plotnik-cli/src/main.rs b/crates/plotnik-cli/src/main.rs index 4a8ffd7a..b67e3465 100644 --- a/crates/plotnik-cli/src/main.rs +++ b/crates/plotnik-cli/src/main.rs @@ -20,8 +20,6 @@ fn main() { source_text: source.source_text, source_file: source.source_file, lang, - query: output.query, - source: output.source, symbols: output.symbols, raw: output.raw, cst: output.cst,