jj icon indicating copy to clipboard operation
jj copied to clipboard

`jj <alias> --help` works, but `jj help <alias>` does not

Open torquestomp opened this issue 1 year ago • 8 comments

Example: Add an alias fetch = git fetch in your config, run jj help fetch. You get error: unrecognized subcommand 'fetch'

torquestomp avatar Jan 22 '24 18:01 torquestomp

I wouldn't say that jj <alias> --help works properly, either.

E.g., if I have an alias aliases.d = ["diff", "-s"], jj d --help is currently the same as jj diff --help. I'd prefer if jj d --help told me that d is an alias. We could also make it print jj diff --help afterwards, or we could not do that.

I think making jj help d act the same way as jj d --help might still be an improvement, though, at least for aliases like your "fetch".

ilyagr avatar Jan 22 '24 20:01 ilyagr

I was hoping this would be a quick in-and-out fix, but it appears that the way help is actually invoked is deep in the internals of clap, so it's not as simple as I hoped. I may come back to this later but I'll unassign for now.

torquestomp avatar Jan 25 '24 21:01 torquestomp

but it appears that the way help is actually invoked is deep in the internals of clap

Yes, I suspect we'll need to take over handling of all help messages in order to fix this.

martinvonz avatar Jan 25 '24 22:01 martinvonz

Rather than implementing help manually, it might make sense to go through visible_alias, which makes help work out of the box without having to reimplement it: https://docs.rs/clap/latest/clap/struct.Command.html#method.visible_alias (i took a look at reimplementing help and it looks decidedly non-trivial, there's lots of digging through clap's reflection API.)

jyn514 avatar Feb 03 '24 04:02 jyn514

ah, i see, aliases can be multiple commands, they don't correspond 1-1 with a subcommand. so visible_alias won't work.

jyn514 avatar Feb 03 '24 05:02 jyn514

for anyone picking this up in the future - the way clap does this internally is https://docs.rs/clap_builder/4.4.18/src/clap_builder/builder/command.rs.html#4474-4487

jyn514 avatar Feb 03 '24 05:02 jyn514

Is there a place where the "not found" error can be checked, and a list of aliases could be listed instead?

joyously avatar Feb 03 '24 14:02 joyously

@joyously do you mean the "unrecognized subcommand" error? yes, but that place is in clap itself: https://github.com/clap-rs/clap/blob/a7e04a53e4a9e310663a0cdb5bfb0753d84b82bd/clap_builder/src/error/format.rs#L529

jyn514 avatar Feb 09 '24 22:02 jyn514