Skip to content

Commit 40686c1

Browse files
committed
add start of diff cmd
1 parent 145be01 commit 40686c1

File tree

1 file changed

+44
-8
lines changed

1 file changed

+44
-8
lines changed

ci/svd2rust-regress/src/main.rs

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,47 @@ pub struct Tests {
7474
/// Print all available test using the specified filters
7575
#[clap(long)]
7676
pub list: bool,
77+
78+
/// Path to an `svd2rust` binary, relative or absolute.
79+
/// Defaults to `target/release/svd2rust[.exe]` of this repository
80+
/// (which must be already built)
81+
#[clap(short = 'p', long = "svd2rust-path", default_value = default_svd2rust())]
82+
pub current_bin_path: PathBuf,
7783
// TODO: Specify smaller subset of tests? Maybe with tags?
7884
// TODO: Compile svd2rust?
7985
}
8086

87+
#[derive(clap::Parser, Debug)]
88+
#[clap(name = "diff")]
89+
pub struct Diffing {
90+
#[clap(long)]
91+
pub base: Option<String>,
92+
93+
#[clap(long)]
94+
pub head: Option<String>,
95+
96+
/// Enable formatting with `rustfmt`
97+
#[clap(short = 'f', long)]
98+
pub format: bool,
99+
100+
#[clap(subcommand)]
101+
pub short: Option<DiffingSub>,
102+
}
103+
104+
#[derive(clap::Parser, Debug)]
105+
pub enum DiffingSub {
106+
Pr
107+
}
108+
109+
#[test]
110+
pub fn diffing_cli_works() {
111+
Diffing::parse_from(["diff", "pr"]);
112+
Diffing::parse_from(["diff", "--base", "", "--head", "\"--atomics\""]);
113+
Diffing::parse_from(["diff", "--base", "\"@master\"", "--head", "\"@pr\""]);
114+
Diffing::parse_from(["diff", "--base", "\"@master\"", "--head", "\"@pr --atomics\""]);
115+
Diffing::parse_from(["diff", "--head", "\"--atomics\""]);
116+
}
117+
81118
impl Tests {
82119
fn run(
83120
&self,
@@ -192,6 +229,7 @@ impl Tests {
192229

193230
#[derive(clap::Subcommand, Debug)]
194231
pub enum Subcommand {
232+
Diff(Diffing),
195233
Tests(Tests),
196234
}
197235

@@ -202,12 +240,6 @@ pub struct Opts {
202240
#[clap(global = true, long, short = 'v', action = clap::ArgAction::Count)]
203241
pub verbose: u8,
204242

205-
/// Path to an `svd2rust` binary, relative or absolute.
206-
/// Defaults to `target/release/svd2rust[.exe]` of this repository
207-
/// (which must be already built)
208-
#[clap(global = true, short = 'p', long = "svd2rust-path", default_value = default_svd2rust())]
209-
pub current_bin_path: PathBuf,
210-
211243
/// Path to an `rustfmt` binary, relative or absolute.
212244
/// Defaults to `$(rustup which rustfmt)`
213245
#[clap(global = true, long)]
@@ -228,6 +260,7 @@ impl Opts {
228260
fn use_rustfmt(&self) -> bool {
229261
match self.subcommand {
230262
Subcommand::Tests(Tests { format, .. }) => format,
263+
Subcommand::Diff(Diffing { format, .. }) => format,
231264
}
232265
}
233266
}
@@ -344,11 +377,14 @@ fn main() -> Result<(), anyhow::Error> {
344377
match &opt.subcommand {
345378
Subcommand::Tests(tests_opts) => {
346379
anyhow::ensure!(
347-
opt.current_bin_path.exists(),
380+
tests_opts.current_bin_path.exists(),
348381
"svd2rust binary does not exist"
349382
);
350383

351-
tests_opts.run(&opt, &opt.current_bin_path, rustfmt_bin_path)?
384+
tests_opts.run(&opt, &tests_opts.current_bin_path, rustfmt_bin_path)?
385+
}
386+
Subcommand::Diff(_diff) => {
387+
todo!()
352388
}
353389
}
354390
}

0 commit comments

Comments
 (0)