Skip to main content

agent_image_diff/
cli.rs

1use clap::{Parser, ValueEnum};
2use std::path::PathBuf;
3
4#[derive(Parser)]
5#[command(name = "agent-image-diff", version, about = "Structured image diff with JSON output for agent workflows")]
6pub struct Cli {
7    /// Path to the baseline (expected) image
8    pub baseline: PathBuf,
9
10    /// Path to the candidate (actual) image
11    pub candidate: PathBuf,
12
13    /// Output format (written to stdout)
14    #[arg(short = 'f', long, default_value = "json", value_enum)]
15    pub format: OutputFormat,
16
17    /// Path to write visual diff image (works alongside any output format)
18    #[arg(short = 'o', long = "output")]
19    pub output: Option<PathBuf>,
20
21    /// Color difference threshold (0.0 = exact match, 1.0 = everything matches)
22    #[arg(short = 't', long, default_value = "0.1")]
23    pub threshold: f64,
24
25    /// Enable anti-aliasing detection (reduces false positives at edges)
26    #[arg(long, default_value = "true")]
27    pub detect_antialias: bool,
28
29    /// Minimum region size in pixels (regions smaller than this are filtered out)
30    #[arg(long, default_value = "25")]
31    pub min_region_size: u32,
32
33    /// Connectivity for region clustering: 4 (cross) or 8 (including diagonals)
34    #[arg(long, default_value = "8")]
35    pub connectivity: u8,
36
37    /// Remove noise clusters smaller than this many pixels before dilation (0 = disabled)
38    #[arg(long, default_value = "25")]
39    pub denoise: u32,
40
41    /// Dilation radius in pixels (expands diff mask to merge nearby changes, 0 = disabled)
42    #[arg(long, default_value = "0")]
43    pub dilate: u32,
44
45    /// Max gap in pixels between regions to merge them (0 = disabled)
46    #[arg(long, default_value = "50")]
47    pub merge_distance: u32,
48
49    /// Exit code behavior
50    #[arg(long, default_value = "diff", value_enum)]
51    pub exit_code: ExitCodeMode,
52
53    /// Include all diagnostic fields in JSON output (dimensions, pixel counts, deltas)
54    #[arg(short = 'v', long)]
55    pub verbose: bool,
56
57    /// Pretty-print JSON output (default is compact single-line)
58    #[arg(long)]
59    pub pretty: bool,
60
61    /// Suppress stdout output; rely on exit code only (0 = match, 1 = diff)
62    #[arg(short = 'q', long)]
63    pub quiet: bool,
64}
65
66#[derive(ValueEnum, Clone)]
67pub enum OutputFormat {
68    Json,
69    Image,
70    Summary,
71}
72
73#[derive(ValueEnum, Clone)]
74pub enum ExitCodeMode {
75    /// Exit 1 if images differ
76    Diff,
77    /// Always exit 0
78    AlwaysZero,
79}