]> git.proxmox.com Git - cargo.git/commitdiff
Auto merge of #11029 - epage:config, r=weihanglo
authorbors <bors@rust-lang.org>
Thu, 1 Sep 2022 06:05:27 +0000 (06:05 +0000)
committerbors <bors@rust-lang.org>
Thu, 1 Sep 2022 06:05:27 +0000 (06:05 +0000)
refactor(cli): Lazy load config

This is trying to clarify `-C` support when it is implemented in #10952

Cargo currently has two initialization states for Config, `Config::default` (process start) and `config.configure` (after parsing args).  The most help we provide for a developer touching this code is a giant `CAUTION` comment in one of the relevant functions.

Currently, #10952 adds another configuration state in the middle where the `current_dir` has been set.

The goal of this PR is to remove that third configuration state by
- Lazy loading `Config::default` so it can be called after parsing `-C`
- Allowing `-C` support to assert that the config isn't loaded yet to catch bugs with it

The hope is this will make the intent of the code clearer and reduce the chance for bugs.

In doing this, there are two intermediate refactorings
- Make help behave like other subcommands
  - Before, we had hacks to intercept raw arguments and to intercept clap errors and assume what their intention was to be able to implement our help system.
  - This flips it around and makes help like any other subcommand,
simplifying cargo initialization.
  - We had to upgrade clap because this exposed a bug where `Command::print_help` wasn't respecting `disable_colored_help(true)`
- Delay fix's access to config

Personally, I also find both changes make the intent of the code clearer.

To review this, I recommend looking at the individual commits.   As this is just refactors, this has no impact on testing.


Trivial merge