Skip to content

Commit 2b3554f

Browse files
committed
Auto merge of #11905 - epage:help_heading, r=weihanglo
fix(cli): Make `--help` easier to browse This mirrors some of the categories from `cargo help` (the man pages) using [`clap::Arg::help_heading`](https://docs.rs/clap/latest/clap/struct.Arg.html#method.help_heading). There are fewer categories to avoid extra vertical space. Instead, they are left int the `Options` category but put first. The goal is to try to make it easier to scan `--help` output as the list of flags can get quite long and its easy to miss what features are there.
2 parents a07a12a + 853102f commit 2b3554f

File tree

70 files changed

+1040
-785
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+1040
-785
lines changed

src/bin/cargo/cli.rs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,9 @@ pub fn cli() -> Command {
523523
Command::new("cargo")
524524
// Subcommands all count their args' display order independently (from 0),
525525
// which makes their args interspersed with global args. This puts global args last.
526-
.next_display_order(1000)
526+
//
527+
// We also want these to come before auto-generated `--help`
528+
.next_display_order(800)
527529
.allow_external_subcommands(true)
528530
// Doesn't mix well with our list of common cargo commands. See clap-rs/clap#3108 for
529531
// opening clap up to allow us to style our help template
@@ -586,9 +588,21 @@ See 'cargo help <command>' for more information on a specific command.\n",
586588
.value_hint(clap::ValueHint::DirPath)
587589
.value_parser(clap::builder::ValueParser::path_buf()),
588590
)
589-
.arg(flag("frozen", "Require Cargo.lock and cache are up to date").global(true))
590-
.arg(flag("locked", "Require Cargo.lock is up to date").global(true))
591-
.arg(flag("offline", "Run without accessing the network").global(true))
591+
.arg(
592+
flag("frozen", "Require Cargo.lock and cache are up to date")
593+
.help_heading(heading::MANIFEST_OPTIONS)
594+
.global(true),
595+
)
596+
.arg(
597+
flag("locked", "Require Cargo.lock is up to date")
598+
.help_heading(heading::MANIFEST_OPTIONS)
599+
.global(true),
600+
)
601+
.arg(
602+
flag("offline", "Run without accessing the network")
603+
.help_heading(heading::MANIFEST_OPTIONS)
604+
.global(true),
605+
)
592606
.arg(multi_opt("config", "KEY=VALUE", "Override a configuration value").global(true))
593607
.arg(
594608
Arg::new("unstable-features")

src/bin/cargo/commands/add.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ Example uses:
7979
])
8080
.arg_manifest_path()
8181
.arg_package("Package to modify")
82-
.arg_quiet()
8382
.arg_dry_run("Don't actually write the manifest")
83+
.arg_quiet()
8484
.next_help_heading("Source")
8585
.args([
8686
clap::Arg::new("path")

src/bin/cargo/commands/bench.rs

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use cargo::ops::{self, TestOptions};
44
pub fn cli() -> Command {
55
subcommand("bench")
66
.about("Execute all benchmarks of a local package")
7-
.arg_quiet()
7+
.next_display_order(0)
88
.arg(
99
Arg::new("BENCHNAME")
1010
.action(ArgAction::Set)
@@ -16,6 +16,19 @@ pub fn cli() -> Command {
1616
.num_args(0..)
1717
.last(true),
1818
)
19+
.arg(flag("no-run", "Compile, but don't run benchmarks"))
20+
.arg(flag(
21+
"no-fail-fast",
22+
"Run all benchmarks regardless of failure",
23+
))
24+
.arg_ignore_rust_version()
25+
.arg_message_format()
26+
.arg_quiet()
27+
.arg_package_spec(
28+
"Package to run benchmarks for",
29+
"Benchmark all packages in the workspace",
30+
"Exclude packages from the benchmark",
31+
)
1932
.arg_targets_all(
2033
"Benchmark only this package's library",
2134
"Benchmark only the specified binary",
@@ -28,26 +41,14 @@ pub fn cli() -> Command {
2841
"Benchmark all benches",
2942
"Benchmark all targets",
3043
)
31-
.arg(flag("no-run", "Compile, but don't run benchmarks"))
32-
.arg_package_spec(
33-
"Package to run benchmarks for",
34-
"Benchmark all packages in the workspace",
35-
"Exclude packages from the benchmark",
36-
)
44+
.arg_features()
3745
.arg_jobs()
3846
.arg_profile("Build artifacts with the specified profile")
39-
.arg_features()
4047
.arg_target_triple("Build for the target triple")
4148
.arg_target_dir()
42-
.arg_manifest_path()
43-
.arg_ignore_rust_version()
44-
.arg_message_format()
45-
.arg(flag(
46-
"no-fail-fast",
47-
"Run all benchmarks regardless of failure",
48-
))
4949
.arg_unit_graph()
5050
.arg_timings()
51+
.arg_manifest_path()
5152
.after_help("Run `cargo help bench` for more detailed information.\n")
5253
}
5354

src/bin/cargo/commands/build.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@ pub fn cli() -> Command {
77
// subcommand aliases are handled in aliased_command()
88
// .alias("b")
99
.about("Compile a local package and all of its dependencies")
10+
.arg_ignore_rust_version()
11+
.arg_future_incompat_report()
12+
.arg_message_format()
1013
.arg_quiet()
1114
.arg_package_spec(
1215
"Package to build (see `cargo help pkgid`)",
1316
"Build all packages in the workspace",
1417
"Exclude packages from the build",
1518
)
16-
.arg_jobs()
1719
.arg_targets_all(
1820
"Build only this package's library",
1921
"Build only the specified binary",
@@ -26,25 +28,24 @@ pub fn cli() -> Command {
2628
"Build all benches",
2729
"Build all targets",
2830
)
31+
.arg_features()
2932
.arg_release("Build artifacts in release mode, with optimizations")
3033
.arg_profile("Build artifacts with the specified profile")
31-
.arg_features()
34+
.arg_jobs()
3235
.arg_target_triple("Build for the target triple")
3336
.arg_target_dir()
3437
.arg(
3538
opt(
3639
"out-dir",
3740
"Copy final artifacts to this directory (unstable)",
3841
)
39-
.value_name("PATH"),
42+
.value_name("PATH")
43+
.help_heading(heading::COMPILATION_OPTIONS),
4044
)
41-
.arg_manifest_path()
42-
.arg_ignore_rust_version()
43-
.arg_message_format()
4445
.arg_build_plan()
4546
.arg_unit_graph()
46-
.arg_future_incompat_report()
4747
.arg_timings()
48+
.arg_manifest_path()
4849
.after_help("Run `cargo help build` for more detailed information.\n")
4950
}
5051

src/bin/cargo/commands/check.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@ pub fn cli() -> Command {
77
// subcommand aliases are handled in aliased_command()
88
// .alias("c")
99
.about("Check a local package and all of its dependencies for errors")
10+
.arg_ignore_rust_version()
11+
.arg_future_incompat_report()
12+
.arg_message_format()
1013
.arg_quiet()
1114
.arg_package_spec(
1215
"Package(s) to check",
1316
"Check all packages in the workspace",
1417
"Exclude packages from the check",
1518
)
16-
.arg_jobs()
1719
.arg_targets_all(
1820
"Check only this package's library",
1921
"Check only the specified binary",
@@ -26,17 +28,15 @@ pub fn cli() -> Command {
2628
"Check all benches",
2729
"Check all targets",
2830
)
31+
.arg_features()
32+
.arg_jobs()
2933
.arg_release("Check artifacts in release mode, with optimizations")
3034
.arg_profile("Check artifacts with the specified profile")
31-
.arg_features()
3235
.arg_target_triple("Check for the target triple")
3336
.arg_target_dir()
34-
.arg_manifest_path()
35-
.arg_ignore_rust_version()
36-
.arg_message_format()
3737
.arg_unit_graph()
38-
.arg_future_incompat_report()
3938
.arg_timings()
39+
.arg_manifest_path()
4040
.after_help("Run `cargo help check` for more detailed information.\n")
4141
}
4242

src/bin/cargo/commands/clean.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ use cargo::util::print_available_packages;
66
pub fn cli() -> Command {
77
subcommand("clean")
88
.about("Remove artifacts that cargo has generated in the past")
9+
.arg_doc("Whether or not to clean just the documentation directory")
910
.arg_quiet()
1011
.arg_package_spec_simple("Package to clean artifacts for")
11-
.arg_manifest_path()
12-
.arg_target_triple("Target triple to clean output for")
13-
.arg_target_dir()
1412
.arg_release("Whether or not to clean release artifacts")
1513
.arg_profile("Clean artifacts of the specified profile")
16-
.arg_doc("Whether or not to clean just the documentation directory")
14+
.arg_target_triple("Target triple to clean output for")
15+
.arg_target_dir()
16+
.arg_manifest_path()
1717
.after_help("Run `cargo help clean` for more detailed information.\n")
1818
}
1919

src/bin/cargo/commands/doc.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,39 +7,39 @@ pub fn cli() -> Command {
77
// subcommand aliases are handled in aliased_command()
88
// .alias("d")
99
.about("Build a package's documentation")
10-
.arg_quiet()
1110
.arg(flag(
1211
"open",
1312
"Opens the docs in a browser after the operation",
1413
))
15-
.arg_package_spec(
16-
"Package to document",
17-
"Document all packages in the workspace",
18-
"Exclude packages from the build",
19-
)
2014
.arg(flag(
2115
"no-deps",
2216
"Don't build documentation for dependencies",
2317
))
2418
.arg(flag("document-private-items", "Document private items"))
25-
.arg_jobs()
19+
.arg_ignore_rust_version()
20+
.arg_message_format()
21+
.arg_quiet()
22+
.arg_package_spec(
23+
"Package to document",
24+
"Document all packages in the workspace",
25+
"Exclude packages from the build",
26+
)
27+
.arg_features()
2628
.arg_targets_lib_bin_example(
2729
"Document only this package's library",
2830
"Document only the specified binary",
2931
"Document all binaries",
3032
"Document only the specified example",
3133
"Document all examples",
3234
)
35+
.arg_jobs()
3336
.arg_release("Build artifacts in release mode, with optimizations")
3437
.arg_profile("Build artifacts with the specified profile")
35-
.arg_features()
3638
.arg_target_triple("Build for the target triple")
3739
.arg_target_dir()
38-
.arg_manifest_path()
39-
.arg_message_format()
40-
.arg_ignore_rust_version()
4140
.arg_unit_graph()
4241
.arg_timings()
42+
.arg_manifest_path()
4343
.after_help("Run `cargo help doc` for more detailed information.\n")
4444
}
4545

src/bin/cargo/commands/fetch.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ pub fn cli() -> Command {
77
subcommand("fetch")
88
.about("Fetch dependencies of a package from the network")
99
.arg_quiet()
10-
.arg_manifest_path()
1110
.arg_target_triple("Fetch dependencies for the target triple")
11+
.arg_manifest_path()
1212
.after_help("Run `cargo help fetch` for more detailed information.\n")
1313
}
1414

src/bin/cargo/commands/fix.rs

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,35 @@ use cargo::ops;
55
pub fn cli() -> Command {
66
subcommand("fix")
77
.about("Automatically fix lint warnings reported by rustc")
8+
.arg(flag("edition", "Fix in preparation for the next edition"))
9+
.arg(flag(
10+
"edition-idioms",
11+
"Fix warnings to migrate to the idioms of an edition",
12+
))
13+
.arg(flag(
14+
"broken-code",
15+
"Fix code even if it already has compiler errors",
16+
))
17+
.arg(flag(
18+
"allow-no-vcs",
19+
"Fix code even if a VCS was not detected",
20+
))
21+
.arg(flag(
22+
"allow-dirty",
23+
"Fix code even if the working directory is dirty",
24+
))
25+
.arg(flag(
26+
"allow-staged",
27+
"Fix code even if the working directory has staged changes",
28+
))
29+
.arg_ignore_rust_version()
30+
.arg_message_format()
831
.arg_quiet()
932
.arg_package_spec(
1033
"Package(s) to fix",
1134
"Fix all packages in the workspace",
1235
"Exclude packages from the fixes",
1336
)
14-
.arg_jobs()
1537
.arg_targets_all(
1638
"Fix only this package's library",
1739
"Fix only the specified binary",
@@ -24,36 +46,14 @@ pub fn cli() -> Command {
2446
"Fix all benches",
2547
"Fix all targets (default)",
2648
)
49+
.arg_features()
50+
.arg_jobs()
2751
.arg_release("Fix artifacts in release mode, with optimizations")
2852
.arg_profile("Build artifacts with the specified profile")
29-
.arg_features()
3053
.arg_target_triple("Fix for the target triple")
3154
.arg_target_dir()
32-
.arg_manifest_path()
33-
.arg_message_format()
34-
.arg(flag(
35-
"broken-code",
36-
"Fix code even if it already has compiler errors",
37-
))
38-
.arg(flag("edition", "Fix in preparation for the next edition"))
39-
.arg(flag(
40-
"edition-idioms",
41-
"Fix warnings to migrate to the idioms of an edition",
42-
))
43-
.arg(flag(
44-
"allow-no-vcs",
45-
"Fix code even if a VCS was not detected",
46-
))
47-
.arg(flag(
48-
"allow-dirty",
49-
"Fix code even if the working directory is dirty",
50-
))
51-
.arg(flag(
52-
"allow-staged",
53-
"Fix code even if the working directory has staged changes",
54-
))
55-
.arg_ignore_rust_version()
5655
.arg_timings()
56+
.arg_manifest_path()
5757
.after_help("Run `cargo help fix` for more detailed information.\n")
5858
}
5959

src/bin/cargo/commands/init.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ use cargo::ops;
55
pub fn cli() -> Command {
66
subcommand("init")
77
.about("Create a new cargo package in an existing directory")
8-
.arg_quiet()
98
.arg(Arg::new("path").action(ArgAction::Set).default_value("."))
10-
.arg(opt("registry", "Registry to use").value_name("REGISTRY"))
119
.arg_new_opts()
10+
.arg(opt("registry", "Registry to use").value_name("REGISTRY"))
11+
.arg_quiet()
1212
.after_help("Run `cargo help init` for more detailed information.\n")
1313
}
1414

0 commit comments

Comments
 (0)