1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
// SPDX-License-Identifier: Apache-2.0 OR MIT
use clap::{Parser, Subcommand};
use hs_intake::{
compare, compare_buildrequires, compare_provides, compare_requires, fedrq, safe_to_backport,
};
#[derive(Parser)]
#[command(
version,
about,
long_about = None,
before_help = concat!(env!("CARGO_PKG_NAME"), " ", env!("CARGO_PKG_VERSION"))
)]
struct Cli {
#[command(subcommand)]
command: Commands,
}
#[derive(Subcommand)]
enum Commands {
/// Compare the BuildRequires of a source package between two branches.
CompareBuildRequires {
/// Source RPM name (e.g. "systemd").
srpm: String,
/// Branch to compare from (e.g. "rawhide").
source_branch: String,
/// Branch to compare to (e.g. "c10s-hyperscale").
target_branch: String,
/// Output as JSON.
#[arg(long)]
json: bool,
/// Also show unchanged entries.
#[arg(long)]
show_unchanged: bool,
},
/// Compare the Provides of a source package between two branches.
CompareProvides {
/// Source RPM name (e.g. "systemd").
srpm: String,
/// Branch to compare from (e.g. "rawhide").
source_branch: String,
/// Branch to compare to (e.g. "c10s-hyperscale").
target_branch: String,
/// Output as JSON.
#[arg(long)]
json: bool,
/// Also show unchanged entries.
#[arg(long)]
show_unchanged: bool,
},
/// Compare the Requires of a source package between two branches.
CompareRequires {
/// Source RPM name (e.g. "systemd").
srpm: String,
/// Branch to compare from (e.g. "rawhide").
source_branch: String,
/// Branch to compare to (e.g. "c10s-hyperscale").
target_branch: String,
/// Output as JSON.
#[arg(long)]
json: bool,
/// Also show unchanged entries.
#[arg(long)]
show_unchanged: bool,
},
/// Check if a source package is safe to backport between branches.
SafeToBackport {
/// Source RPM name (e.g. "systemd").
srpm: String,
/// Branch to backport to (e.g. "c10s-hyperscale").
target_branch: String,
/// Branch to take the package from (e.g. "rawhide").
source_branch: String,
/// Output as JSON.
#[arg(long)]
json: bool,
/// Additional branches to check for reverse dependencies (comma-separated).
#[arg(long, value_delimiter = ',')]
also_check: Vec<String>,
},
}
fn run_compare(
result: Result<compare::CompareResult, fedrq::Error>,
label: &str,
source_branch: &str,
target_branch: &str,
json: bool,
show_unchanged: bool,
) {
match result {
Ok(cmp) => {
if json {
println!("{}", serde_json::to_string_pretty(&cmp).unwrap());
} else {
compare::print_result(&cmp, label, source_branch, target_branch, show_unchanged);
}
}
Err(e) => {
eprintln!("Error: {e}");
std::process::exit(1);
}
}
}
fn main() {
sandogasa_cli::init();
let cli = sandogasa_cli::parse_with_defaults::<Cli>(env!("CARGO_PKG_NAME"));
match cli.command {
Commands::CompareBuildRequires {
srpm,
source_branch,
target_branch,
json,
show_unchanged,
} => {
let result =
compare_buildrequires::compare_buildrequires(&srpm, &source_branch, &target_branch);
run_compare(
result,
"BuildRequire",
&source_branch,
&target_branch,
json,
show_unchanged,
);
}
Commands::CompareProvides {
srpm,
source_branch,
target_branch,
json,
show_unchanged,
} => {
let result = compare_provides::compare_provides(&srpm, &source_branch, &target_branch);
run_compare(
result,
"Provide",
&source_branch,
&target_branch,
json,
show_unchanged,
);
}
Commands::CompareRequires {
srpm,
source_branch,
target_branch,
json,
show_unchanged,
} => {
let result = compare_requires::compare_requires(&srpm, &source_branch, &target_branch);
run_compare(
result,
"Require",
&source_branch,
&target_branch,
json,
show_unchanged,
);
}
Commands::SafeToBackport {
srpm,
target_branch,
source_branch,
json,
also_check,
} => {
match safe_to_backport::safe_to_backport(
&srpm,
&target_branch,
&source_branch,
&also_check,
) {
Ok(result) => {
if json {
println!("{}", serde_json::to_string_pretty(&result).unwrap());
} else {
safe_to_backport::print_result(
&result,
&srpm,
&target_branch,
&source_branch,
);
}
if !result.safe {
std::process::exit(1);
}
}
Err(e) => {
eprintln!("Error: {e}");
std::process::exit(1);
}
}
}
}
}