Skip to content

Commit

Permalink
refactor(cli): Make it obvious that the cases are mutually exclusive
Browse files Browse the repository at this point in the history
  • Loading branch information
epage committed Feb 22, 2024
1 parent ad85ef4 commit 808b4f6
Showing 1 changed file with 20 additions and 28 deletions.
48 changes: 20 additions & 28 deletions src/bin/cargo/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,46 +48,38 @@ pub fn main(gctx: &mut GlobalContext) -> CliResult {

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

let is_verbose = expanded_args.verbose() > 0;

if expanded_args
.get_one::<String>("unstable-features")
.map(String::as_str)
== Some("help")
{
print_zhelp(gctx);
return Ok(());
}

let is_verbose = expanded_args.verbose() > 0;
if expanded_args.flag("version") {
} else if expanded_args.flag("version") {
let version = get_version_string(is_verbose);
drop_print!(gctx, "{}", version);
return Ok(());
}

if let Some(code) = expanded_args.get_one::<String>("explain") {
} else if let Some(code) = expanded_args.get_one::<String>("explain") {
let mut procss = gctx.load_global_rustc(None)?.process();
procss.arg("--explain").arg(code).exec()?;
return Ok(());
}

if expanded_args.flag("list") {
} else if expanded_args.flag("list") {
print_list(gctx, is_verbose);
return Ok(());
}

let (cmd, subcommand_args) = match expanded_args.subcommand() {
Some((cmd, args)) => (cmd, args),
_ => {
// No subcommand provided.
cli(gctx).print_help()?;
return Ok(());
}
};
let exec = Exec::infer(cmd)?;
config_configure(gctx, &expanded_args, subcommand_args, global_args, &exec)?;
super::init_git(gctx);
} else {
let (cmd, subcommand_args) = match expanded_args.subcommand() {
Some((cmd, args)) => (cmd, args),
_ => {
// No subcommand provided.
cli(gctx).print_help()?;
return Ok(());
}
};
let exec = Exec::infer(cmd)?;
config_configure(gctx, &expanded_args, subcommand_args, global_args, &exec)?;
super::init_git(gctx);

exec.exec(gctx, subcommand_args)
exec.exec(gctx, subcommand_args)?;
}
Ok(())
}

fn print_zhelp(gctx: &GlobalContext) {
Expand Down

0 comments on commit 808b4f6

Please sign in to comment.