Skip to content

Commit f5a1b9c

Browse files
committed
Make --completions conflict with workload specification
1 parent 0872b7c commit f5a1b9c

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/bin/flamegraph.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ struct Opt {
1313
pid: Option<u32>,
1414

1515
/// Generate shell completions for the given shell.
16-
#[structopt(long = "completions")]
16+
#[structopt(long = "completions", conflicts_with = "pid")]
1717
completions: Option<structopt::clap::Shell>,
1818

1919
#[structopt(flatten)]
@@ -26,8 +26,18 @@ fn main() -> anyhow::Result<()> {
2626
let opt = Opt::from_args();
2727

2828
if let Some(shell) = opt.completions {
29-
Opt::clap().gen_completions_to("flamegraph", shell, &mut std::io::stdout().lock());
30-
return Ok(());
29+
return match opt.trailing_arguments.is_empty() {
30+
true => Ok(Opt::clap().gen_completions_to(
31+
"flamegraph",
32+
shell,
33+
&mut std::io::stdout().lock(),
34+
)),
35+
false => {
36+
return Err(anyhow!(
37+
"command arguments cannot be used with --completions <completions>"
38+
))
39+
}
40+
};
3141
}
3242

3343
let workload = match (opt.pid, opt.trailing_arguments.is_empty()) {

0 commit comments

Comments
 (0)