Skip to content

Conversation

@weihanglo
Copy link
Member

@weihanglo weihanglo commented Dec 25, 2025

Blocked on #16430

What does this PR try to resolve?

This allows cargo help to display manpages for nested subcommand,
such as cargo report future-incompat.

The argument of cargo help can be

  • A single <COMMAND>, such as cargo help build
    or cargo help report-future-incompat (dash-joined)
  • Multiple <COMMAND>s, such as cargo help report future-incompat

This dash-joined form helps man-page user learn from existing convention.
The multiple commands form is straightforward for normal users.

How to test and review this PR?

cargo run -- help rpeort-future-incompat
cargo run -- help report-future-incompatibilities
cargo run -- help report future-incompat
cargo run -- help report future-incompatibilities

@rustbot rustbot added A-cli Area: Command-line interface, option parsing, etc. A-cli-help Area: built-in command-line help A-documenting-cargo-itself Area: Cargo's documentation A-future-incompat Area: future incompatible reporting Command-report labels Dec 25, 2025
@weihanglo weihanglo force-pushed the cargo-help branch 2 times, most recently from 525addb to 286129a Compare December 26, 2025 02:01
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will need an team FCP

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about completions?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can clap complete cargo help report fu<tab>? I guess it is not really supported and we might need to auto-complete in dash-joined form.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

num_args(1..) are assumed to not be hierarchical so it can't. We don't have external subcommand completers yet, so switching to that wouldn't help.

Hmm, just realized we might not be offering completions for built-in help with the new completion engine. The old one would instantiate help in special way that automatically generated subcommands for every subcommand, recursively.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with the new completion engine

What is this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original clap completion system auto-generated completion files files similar to what we hand write in cargo. The new completion system is what Cargo is migrating to and what you wrote code for.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah thanks. I thought clap_completion going to get a new engine 😆.

Comment on lines 174 to 200
#[derive(Clone)]
enum CommandKind {
Primary,
/// Contains the primary manpage name
Alias(String),
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we care to track this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For getting the original man page dash-joined name.

Copy link
Member Author

@weihanglo weihanglo Dec 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made the intent more outstanding by renaming it to ManPageLookup

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still isn't making sense since all we do is immediately

    let subcommand = match lookup {
        ManPageLookup::Direct => subcommand,
        ManPageLookup::RedirectTo(primary) => primary,
    };

@weihanglo weihanglo force-pushed the cargo-help branch 3 times, most recently from 6eb4401 to 459fd78 Compare December 29, 2025 20:10
@rustbot

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-author Status: The marked PR is awaiting some action (such as code changes) from the PR author. label Dec 29, 2025
Comment on lines +23 to +38
### Manifest Options

{{#options}}
{{> options-locked }}
{{/options}}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we be bothering if these don't do anything

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or we can hide them also in --help text. Either works for me but man page and help text should be aligned.

&[OsStr::new(subcommand), OsStr::new("--help")],
)?;
}
if super::builtin_exec(subcommand).is_none() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I think in a previous iteration, you had used !option.is_some(). One advantage of that is it makes the fact that this is negative logic upfront.

Thoughts?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, is there a reason you swapped the order of the cases instead of doing option.is_some()?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, for an early return later

Some(s) => s,
None => return Ok(false),
};
if super::builtin_exec(subcommand).is_none() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: another case of option.is_none()

Comment on lines 56 to 63
if super::builtin_exec(&subcommand).is_none() {
// If not built-in, try giving `--help` to external command.
crate::execute_external_subcommand(
gctx,
&subcommand,
&[OsStr::new(&subcommand), OsStr::new("--help")],
)?;
} else {
crate::execute_internal_subcommand(gctx, &[OsStr::new(&subcommand), OsStr::new("--help")])?;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doesn't this need an early return?

Comment on lines +69 to 68
if !is_valid_builtin_command_path(&args_command) {
let command_str = args_command.join(" ");
let err = anyhow::format_err!(
"no such command: `{command_str}`\n\n\
help: view all installed commands with `cargo --list`",
);
return Err(err.into());
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cargo --list won't help for cargo report foo

@rustbot

This comment has been minimized.

So that when snapshotting, windows target won't be redacted by snapbox
This allows `cargo help` to display manpages for nested subcommand,
such as `cargo report future-incompat`.

The argument of `cargo help` can be

* A single `<COMMAND>`, such as `cargo help build`
  or `cargo help report-future-incompat` (dash-joined)
* Multiple `<COMMAND>`s, such as `cargo help report future-incompat`

This dash-joined form helps man-page user learn from existing convention.
The multiple commands form is straightforward for normal users.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-cli Area: Command-line interface, option parsing, etc. A-cli-help Area: built-in command-line help A-documenting-cargo-itself Area: Cargo's documentation A-future-incompat Area: future incompatible reporting Command-report S-waiting-on-author Status: The marked PR is awaiting some action (such as code changes) from the PR author.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants