Skip to content

Commit 1834244

Browse files
committed
refactor(cli): Allow calling config_configure without Exec
1 parent 808b4f6 commit 1834244

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

src/bin/cargo/cli.rs

+14-6
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,13 @@ pub fn main(gctx: &mut GlobalContext) -> CliResult {
7474
}
7575
};
7676
let exec = Exec::infer(cmd)?;
77-
config_configure(gctx, &expanded_args, subcommand_args, global_args, &exec)?;
77+
config_configure(
78+
gctx,
79+
&expanded_args,
80+
Some(subcommand_args),
81+
global_args,
82+
Some(&exec),
83+
)?;
7884
super::init_git(gctx);
7985

8086
exec.exec(gctx, subcommand_args)?;
@@ -365,16 +371,18 @@ For more information, see issue #12207 <https://github.com/rust-lang/cargo/issue
365371
fn config_configure(
366372
gctx: &mut GlobalContext,
367373
args: &ArgMatches,
368-
subcommand_args: &ArgMatches,
374+
subcommand_args: Option<&ArgMatches>,
369375
global_args: GlobalArgs,
370-
exec: &Exec,
376+
exec: Option<&Exec>,
371377
) -> CliResult {
372-
let arg_target_dir = &subcommand_args.value_of_path("target-dir", gctx);
378+
let arg_target_dir = &subcommand_args.and_then(|a| a.value_of_path("target-dir", gctx));
373379
let mut verbose = global_args.verbose + args.verbose();
374380
// quiet is unusual because it is redefined in some subcommands in order
375381
// to provide custom help text.
376-
let mut quiet = args.flag("quiet") || subcommand_args.flag("quiet") || global_args.quiet;
377-
if matches!(exec, Exec::Manifest(_)) && !quiet {
382+
let mut quiet = args.flag("quiet")
383+
|| subcommand_args.map(|a| a.flag("quiet")).unwrap_or_default()
384+
|| global_args.quiet;
385+
if matches!(exec, Some(Exec::Manifest(_))) && !quiet {
378386
// Verbosity is shifted quieter for `Exec::Manifest` as it is can be used as if you ran
379387
// `cargo install` and we especially shouldn't pollute programmatic output.
380388
//

0 commit comments

Comments
 (0)