Skip to content

Commit a8142ea

Browse files
cgzonesetke
authored andcommitted
Use ArgGroup to simplify conflicts
Also now `checksec -m --no-color` fails with help shown.
1 parent 01b0bbf commit a8142ea

File tree

1 file changed

+16
-27
lines changed

1 file changed

+16
-27
lines changed

src/main.rs

Lines changed: 16 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ extern crate ignore;
55
extern crate serde_json;
66
extern crate sysinfo;
77

8-
use clap::{crate_authors, crate_description, crate_version, Arg, Command};
8+
use clap::{
9+
crate_authors, crate_description, crate_version, Arg, ArgGroup, Command,
10+
};
911
use goblin::error::Error;
1012
#[cfg(feature = "macho")]
1113
use goblin::mach::Mach;
@@ -227,23 +229,15 @@ fn main() {
227229
.long("directory")
228230
.value_name("DIRECTORY")
229231
.help("Target directory")
230-
.takes_value(true)
231-
.conflicts_with("file")
232-
.conflicts_with("pid")
233-
.conflicts_with("process")
234-
.conflicts_with("process-all"),
232+
.takes_value(true),
235233
)
236234
.arg(
237235
Arg::new("file")
238236
.short('f')
239237
.long("file")
240238
.value_name("FILE")
241239
.help("Target file")
242-
.takes_value(true)
243-
.conflicts_with("directory")
244-
.conflicts_with("pid")
245-
.conflicts_with("process")
246-
.conflicts_with("process-all"),
240+
.takes_value(true),
247241
)
248242
.arg(
249243
Arg::new("json")
@@ -256,8 +250,10 @@ fn main() {
256250
.short('m')
257251
.long("maps")
258252
.help("Include process memory maps (Linux only)")
253+
.requires("pid")
259254
.requires("process")
260-
.requires("process-all"),
255+
.requires("process-all")
256+
.conflicts_with_all(&["directory", "file"]),
261257
)
262258
.arg(
263259
Arg::new("no-color")
@@ -272,11 +268,7 @@ fn main() {
272268
"Process ID of running process to check\n\
273269
(comma separated for multiple PIDs)",
274270
)
275-
.takes_value(true)
276-
.conflicts_with("directory")
277-
.conflicts_with("file")
278-
.conflicts_with("process")
279-
.conflicts_with("process-all"),
271+
.takes_value(true),
280272
)
281273
.arg(
282274
Arg::new("pretty")
@@ -290,21 +282,18 @@ fn main() {
290282
.long("process")
291283
.value_name("NAME")
292284
.help("Name of running process to check")
293-
.takes_value(true)
294-
.conflicts_with("directory")
295-
.conflicts_with("file")
296-
.conflicts_with("pid")
297-
.conflicts_with("process-all"),
285+
.takes_value(true),
298286
)
299287
.arg(
300288
Arg::new("process-all")
301289
.short('P')
302290
.long("process-all")
303-
.help("Check all running processes")
304-
.conflicts_with("directory")
305-
.conflicts_with("file")
306-
.conflicts_with("pid")
307-
.conflicts_with("process"),
291+
.help("Check all running processes"),
292+
)
293+
.group(
294+
ArgGroup::new("operation")
295+
.args(&["directory", "file", "pid", "process", "process-all"])
296+
.required(true),
308297
)
309298
.get_matches();
310299

0 commit comments

Comments
 (0)