Skip to content

Commit 808b4f6

Browse files
committed
refactor(cli): Make it obvious that the cases are mutually exclusive
1 parent ad85ef4 commit 808b4f6

File tree

1 file changed

+20
-28
lines changed

1 file changed

+20
-28
lines changed

src/bin/cargo/cli.rs

Lines changed: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -48,46 +48,38 @@ pub fn main(gctx: &mut GlobalContext) -> CliResult {
4848

4949
let (expanded_args, global_args) = expand_aliases(gctx, args, vec![])?;
5050

51+
let is_verbose = expanded_args.verbose() > 0;
52+
5153
if expanded_args
5254
.get_one::<String>("unstable-features")
5355
.map(String::as_str)
5456
== Some("help")
5557
{
5658
print_zhelp(gctx);
57-
return Ok(());
58-
}
59-
60-
let is_verbose = expanded_args.verbose() > 0;
61-
if expanded_args.flag("version") {
59+
} else if expanded_args.flag("version") {
6260
let version = get_version_string(is_verbose);
6361
drop_print!(gctx, "{}", version);
64-
return Ok(());
65-
}
66-
67-
if let Some(code) = expanded_args.get_one::<String>("explain") {
62+
} else if let Some(code) = expanded_args.get_one::<String>("explain") {
6863
let mut procss = gctx.load_global_rustc(None)?.process();
6964
procss.arg("--explain").arg(code).exec()?;
70-
return Ok(());
71-
}
72-
73-
if expanded_args.flag("list") {
65+
} else if expanded_args.flag("list") {
7466
print_list(gctx, is_verbose);
75-
return Ok(());
76-
}
77-
78-
let (cmd, subcommand_args) = match expanded_args.subcommand() {
79-
Some((cmd, args)) => (cmd, args),
80-
_ => {
81-
// No subcommand provided.
82-
cli(gctx).print_help()?;
83-
return Ok(());
84-
}
85-
};
86-
let exec = Exec::infer(cmd)?;
87-
config_configure(gctx, &expanded_args, subcommand_args, global_args, &exec)?;
88-
super::init_git(gctx);
67+
} else {
68+
let (cmd, subcommand_args) = match expanded_args.subcommand() {
69+
Some((cmd, args)) => (cmd, args),
70+
_ => {
71+
// No subcommand provided.
72+
cli(gctx).print_help()?;
73+
return Ok(());
74+
}
75+
};
76+
let exec = Exec::infer(cmd)?;
77+
config_configure(gctx, &expanded_args, subcommand_args, global_args, &exec)?;
78+
super::init_git(gctx);
8979

90-
exec.exec(gctx, subcommand_args)
80+
exec.exec(gctx, subcommand_args)?;
81+
}
82+
Ok(())
9183
}
9284

9385
fn print_zhelp(gctx: &GlobalContext) {

0 commit comments

Comments
 (0)