1use clap::{Parser, Subcommand, ValueEnum};
2use std::path::PathBuf;
3
4#[derive(Parser)]
5#[command(name = "struct-audit")]
6#[command(
7 author,
8 version,
9 about = "Analyze binary memory layouts to detect padding inefficiencies"
10)]
11#[command(
12 long_about = "struct-audit parses DWARF debugging information to visualize the physical \
13layout of data structures, detect padding holes, and analyze cache line efficiency.\n\n\
14Example:\n struct-audit inspect ./target/debug/myapp --filter MyStruct"
15)]
16pub struct Cli {
17 #[command(subcommand)]
18 pub command: Commands,
19}
20
21#[derive(Subcommand)]
22pub enum Commands {
23 Inspect {
25 #[arg(value_name = "BINARY")]
27 binary: PathBuf,
28
29 #[arg(short, long)]
31 filter: Option<String>,
32
33 #[arg(short, long, value_enum, default_value = "table")]
35 output: OutputFormat,
36
37 #[arg(short, long, value_enum, default_value = "name")]
39 sort_by: SortField,
40
41 #[arg(short = 'n', long)]
43 top: Option<usize>,
44
45 #[arg(long)]
47 min_padding: Option<u64>,
48
49 #[arg(long)]
51 no_color: bool,
52
53 #[arg(long, default_value = "64", value_parser = clap::value_parser!(u32).range(1..))]
55 cache_line: u32,
56
57 #[arg(long)]
59 pretty: bool,
60 },
61
62 Diff {
64 #[arg(value_name = "OLD")]
66 old: PathBuf,
67
68 #[arg(value_name = "NEW")]
70 new: PathBuf,
71
72 #[arg(short, long)]
74 filter: Option<String>,
75
76 #[arg(short, long, value_enum, default_value = "table")]
78 output: OutputFormat,
79
80 #[arg(long, default_value = "64", value_parser = clap::value_parser!(u32).range(1..))]
82 cache_line: u32,
83
84 #[arg(long)]
86 fail_on_regression: bool,
87 },
88
89 Check {
91 #[arg(value_name = "BINARY")]
93 binary: PathBuf,
94
95 #[arg(short, long, default_value = ".struct-audit.yaml")]
97 config: PathBuf,
98
99 #[arg(long, default_value = "64", value_parser = clap::value_parser!(u32).range(1..))]
101 cache_line: u32,
102 },
103}
104
105#[derive(Copy, Clone, PartialEq, Eq, ValueEnum)]
106pub enum OutputFormat {
107 Table,
108 Json,
109}
110
111#[derive(Copy, Clone, PartialEq, Eq, ValueEnum)]
112pub enum SortField {
113 Name,
115 Size,
117 Padding,
119 PaddingPct,
121}