Skip to content

Commit a6c0d43

Browse files
committed
Auto merge of #12157 - kornelski:binargs, r=weihanglo
Tweak build help to clarify role of --bin From [user feedback](https://internals.rust-lang.org/t/pre-issue-feature-request-give-me-the-option-to-not-build-a-target/18852/5) the `--bin`'s description "Build only the specified binary" could be understood as "Don't build lib" rather than "Build this bin (with lib) and not other bins". I don't know if a better wording explaining subtelty of lib+bin crates would fit in the small space of CLI help. However, reordering the args to show `--bin` after `--bins` rather than after `--lib` gives it a more accurate context. So I've merely put the `--bin` (and test/bench/example) after their plural counterpart. I've also noticed an issue with clap [inserting global args between subcommand's args](clap-rs/clap#4920), and `--locked` definitely doesn't belong right between the two bin args. I've added a workaround for that issue. The workaround is otherwise harmless, and shouldn't cause problems if clap decides to update sort order of subcommands. Changes this: ```text --lib Build only this package's library --bin [<NAME>] Build only the specified binary --locked Require Cargo.lock is up to date --bins Build all binaries --offline Run without accessing the network --config <KEY=VALUE> Override a configuration value --example [<NAME>] Build only the specified example --examples Build all examples -Z <FLAG> Unstable (nightly-only) flags to Cargo, see 'cargo -Z help' for details --test [<NAME>] Build only the specified test target --tests Build all tests --bench [<NAME>] Build only the specified bench target --benches Build all benches ``` to this: ```text --lib Build only this package's library --bins Build all binaries --bin [<NAME>] Build only the specified binary --examples Build all examples --example [<NAME>] Build only the specified example --tests Build all tests --test [<NAME>] Build only the specified test target --benches Build all benches --bench [<NAME>] Build only the specified bench target […] --locked Require Cargo.lock is up to date --offline Run without accessing the network --config <KEY=VALUE> Override a configuration value -Z <FLAG> Unstable (nightly-only) flags to Cargo, see 'cargo -Z help' for details ```
2 parents 2015080 + 75a1dd0 commit a6c0d43

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

src/bin/cargo/cli.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,9 @@ pub fn cli() -> Command {
440440
"cargo [OPTIONS] [COMMAND]"
441441
};
442442
Command::new("cargo")
443+
// Subcommands all count their args' display order independently (from 0),
444+
// which makes their args interspersed with global args. This puts global args last.
445+
.next_display_order(1000)
443446
.allow_external_subcommands(true)
444447
// Doesn't mix well with our list of common cargo commands. See clap-rs/clap#3108 for
445448
// opening clap up to allow us to style our help template

src/cargo/util/command_prelude.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,10 @@ pub trait CommandExt: Sized {
9191
all: &'static str,
9292
) -> Self {
9393
self.arg_targets_lib_bin_example(lib, bin, bins, example, examples)
94-
._arg(optional_multi_opt("test", "NAME", test))
9594
._arg(flag("tests", tests))
96-
._arg(optional_multi_opt("bench", "NAME", bench))
95+
._arg(optional_multi_opt("test", "NAME", test))
9796
._arg(flag("benches", benches))
97+
._arg(optional_multi_opt("bench", "NAME", bench))
9898
._arg(flag("all-targets", all))
9999
}
100100

@@ -107,10 +107,10 @@ pub trait CommandExt: Sized {
107107
examples: &'static str,
108108
) -> Self {
109109
self._arg(flag("lib", lib))
110-
._arg(optional_multi_opt("bin", "NAME", bin))
111110
._arg(flag("bins", bins))
112-
._arg(optional_multi_opt("example", "NAME", example))
111+
._arg(optional_multi_opt("bin", "NAME", bin))
113112
._arg(flag("examples", examples))
113+
._arg(optional_multi_opt("example", "NAME", example))
114114
}
115115

116116
fn arg_targets_bins_examples(

0 commit comments

Comments
 (0)