Skip to main content

semver_analyzer_core/
cli.rs

1//! Shared CLI argument structs for the semver-analyzer.
2//!
3//! These structs define the common flags shared across all language
4//! implementations. Language crates use `#[command(flatten)]` to include
5//! them and add their own language-specific flags.
6
7use clap::Args;
8use std::path::PathBuf;
9
10/// Shared logging/tracing arguments available to all commands.
11///
12/// Language crates and command structs flatten this to get consistent
13/// `--log-file` and `--log-level` flags.
14#[derive(Args, Debug, Clone)]
15pub struct LoggingArgs {
16    /// Path to a log file for debug/trace output.
17    /// When set, all tracing events at the configured level are written here.
18    #[arg(long, help_heading = "Logging")]
19    pub log_file: Option<PathBuf>,
20
21    /// Log level filter (trace, debug, info, warn, error).
22    /// Controls file output verbosity. Stderr progress display is always shown.
23    #[arg(long, default_value = "info", help_heading = "Logging")]
24    pub log_level: String,
25}
26
27/// Common arguments for the `analyze` command.
28///
29/// Language crates flatten this into their own `XxxAnalyzeArgs` struct
30/// and add language-specific flags (e.g., `--build-command` for TypeScript).
31#[derive(Args, Debug, Clone)]
32pub struct CommonAnalyzeArgs {
33    #[command(flatten)]
34    pub logging: LoggingArgs,
35
36    /// Path to the git repository.
37    #[arg(long)]
38    pub repo: PathBuf,
39
40    /// Git ref to compare from (the "old" version).
41    #[arg(long)]
42    pub from: String,
43
44    /// Git ref to compare to (the "new" version).
45    #[arg(long)]
46    pub to: String,
47
48    /// Output file path (writes JSON). Defaults to stdout.
49    #[arg(short, long)]
50    pub output: Option<PathBuf>,
51
52    /// Use the behavioral analysis (BU) pipeline instead of the default
53    /// source-level diff (SD) pipeline.
54    ///
55    /// The BU pipeline uses test-delta heuristics and optional LLM inference
56    /// to detect behavioral breaking changes. The default SD pipeline produces
57    /// deterministic, AST-based source-level change facts.
58    #[arg(long, help_heading = "Pipeline")]
59    pub behavioral: bool,
60
61    /// Backwards-compatible alias for the default pipeline (no-op).
62    /// The SD pipeline is now the default; this flag is accepted but ignored.
63    #[arg(long, hide = true)]
64    pub pipeline_v2: bool,
65
66    /// Skip LLM-based behavioral analysis (static analysis only).
67    #[arg(long, help_heading = "LLM Options")]
68    pub no_llm: bool,
69
70    /// Command to invoke for LLM analysis.
71    /// The prompt is passed as the final argument.
72    #[arg(long, help_heading = "LLM Options")]
73    pub llm_command: Option<String>,
74
75    /// Send ALL files with changed exported functions to the LLM,
76    /// not just files that have associated test changes.
77    /// Only used with --behavioral pipeline.
78    #[arg(long, requires = "behavioral", help_heading = "LLM Options")]
79    pub llm_all_files: bool,
80
81    /// Timeout in seconds for each LLM invocation.
82    #[arg(long, default_value = "120", help_heading = "LLM Options")]
83    pub llm_timeout: u64,
84}
85
86/// Common arguments for the `extract` command.
87#[derive(Args, Debug, Clone)]
88pub struct CommonExtractArgs {
89    #[command(flatten)]
90    pub logging: LoggingArgs,
91
92    /// Path to the git repository.
93    #[arg(long)]
94    pub repo: PathBuf,
95
96    /// Git ref (tag, branch, or commit SHA) to extract from.
97    #[arg(long, name = "ref")]
98    pub git_ref: String,
99
100    /// Output file path (writes JSON). Defaults to stdout.
101    #[arg(short, long)]
102    pub output: Option<PathBuf>,
103}
104
105/// Arguments for the `diff` command (language-agnostic).
106#[derive(Args, Debug, Clone)]
107pub struct DiffArgs {
108    #[command(flatten)]
109    pub logging: LoggingArgs,
110
111    /// Path to the "from" API surface JSON file.
112    #[arg(long)]
113    pub from: PathBuf,
114
115    /// Path to the "to" API surface JSON file.
116    #[arg(long)]
117    pub to: PathBuf,
118
119    /// Output file path (writes JSON). Defaults to stdout.
120    #[arg(short, long)]
121    pub output: Option<PathBuf>,
122}
123
124/// Common arguments for the `konveyor` command.
125#[derive(Args, Debug, Clone)]
126pub struct CommonKonveyorArgs {
127    #[command(flatten)]
128    pub logging: LoggingArgs,
129
130    /// Path to a pre-existing AnalysisReport JSON file.
131    /// Mutually exclusive with --repo/--from/--to.
132    #[arg(long, conflicts_with_all = ["repo", "from", "to"])]
133    pub from_report: Option<PathBuf>,
134
135    /// Path to the git repository (runs full analysis pipeline).
136    #[arg(long, required_unless_present = "from_report")]
137    pub repo: Option<PathBuf>,
138
139    /// Git ref to compare from (the "old" version).
140    #[arg(long, required_unless_present = "from_report")]
141    pub from: Option<String>,
142
143    /// Git ref to compare to (the "new" version).
144    #[arg(long, required_unless_present = "from_report")]
145    pub to: Option<String>,
146
147    /// Output directory for the generated ruleset.
148    #[arg(long)]
149    pub output_dir: PathBuf,
150
151    /// Use the behavioral analysis (BU) pipeline instead of the default
152    /// source-level diff (SD) pipeline. Only used in --repo mode.
153    #[arg(long, help_heading = "Pipeline")]
154    pub behavioral: bool,
155
156    /// Backwards-compatible alias for the default pipeline (no-op).
157    #[arg(long, hide = true)]
158    pub pipeline_v2: bool,
159
160    /// Skip LLM-based behavioral analysis (static analysis only).
161    /// Only used when running analysis internally (--repo mode).
162    #[arg(long, help_heading = "LLM Options")]
163    pub no_llm: bool,
164
165    /// Command to invoke for LLM analysis.
166    #[arg(long, help_heading = "LLM Options")]
167    pub llm_command: Option<String>,
168
169    /// Send ALL files with changed exported functions to the LLM.
170    /// Only used with --behavioral pipeline.
171    #[arg(long, requires = "behavioral", help_heading = "LLM Options")]
172    pub llm_all_files: bool,
173
174    /// Timeout in seconds for each LLM invocation.
175    #[arg(long, default_value = "120", help_heading = "LLM Options")]
176    pub llm_timeout: u64,
177
178    /// Disable rule consolidation (keep one rule per declaration change).
179    #[arg(long, help_heading = "Rule Generation")]
180    pub no_consolidate: bool,
181
182    /// Path to a YAML file with regex-based rename patterns.
183    #[arg(long, help_heading = "Rule Generation")]
184    pub rename_patterns: Option<PathBuf>,
185}