clap-rs / clap

A full featured, fast Command Line Argument Parser for Rust
docs.rs/clap
Apache License 2.0
13.64k stars 1.02k forks source link

Fish completions include --no-files on subcommands #5552

Closed Mawdac closed 4 days ago

Mawdac commented 6 days ago

Hello! I first reported this issue downstream in https://github.com/MilesCranmer/rip2. The issue is that the completions generated for fish include -f which prevents files from being included in completion, which in this case is not desired.

Original issue: https://github.com/MilesCranmer/rip2/issues/39

Since I'm not familiar with rust I'll just elaborate on the issue itself, here are the completions generated from rip2:

complete -c rip -n "__fish_use_subcommand" -l graveyard -d 'Directory where deleted files rest' -r -F
complete -c rip -n "__fish_use_subcommand" -s d -l decompose -d 'Permanently deletes the graveyard'
complete -c rip -n "__fish_use_subcommand" -s s -l seance -d 'Prints files that were deleted in the current directory'
complete -c rip -n "__fish_use_subcommand" -s u -l unbury -d 'Restore the specified files or the last file if none are specified'
complete -c rip -n "__fish_use_subcommand" -s i -l inspect -d 'Print some info about TARGET before burying'
complete -c rip -n "__fish_use_subcommand" -s h -l help -d 'Print help'
complete -c rip -n "__fish_use_subcommand" -s V -l version -d 'Print version'
complete -c rip -n "__fish_use_subcommand" -f -a "completions" -d 'Generate shell completions file'
complete -c rip -n "__fish_use_subcommand" -f -a "graveyard" -d 'Print the graveyard path'
complete -c rip -n "__fish_use_subcommand" -f -a "help" -d 'Print this message or the help of the given subcommand(s)'
complete -c rip -n "__fish_seen_subcommand_from completions" -s h -l help -d 'Print help'
complete -c rip -n "__fish_seen_subcommand_from graveyard" -s s -l seance -d 'Get the graveyard subdirectory of the current directory'
complete -c rip -n "__fish_seen_subcommand_from graveyard" -s h -l help -d 'Print help'
complete -c rip -n "__fish_seen_subcommand_from help; and not __fish_seen_subcommand_from completions; and not __fish_seen_subcommand_from graveyard; and not __fish_seen_subcommand_from help" -f -a "completions" -d 'Generate shell completions file'
complete -c rip -n "__fish_seen_subcommand_from help; and not __fish_seen_subcommand_from completions; and not __fish_seen_subcommand_from graveyard; and not __fish_seen_subcommand_from help" -f -a "graveyard" -d 'Print the graveyard path'
complete -c rip -n "__fish_seen_subcommand_from help; and not __fish_seen_subcommand_from completions; and not __fish_seen_subcommand_from graveyard; and not __fish_seen_subcommand_from help" -f -a "help" -d 'Print this message or the help of the given subcommand(s)'

And it's these 3 that (in my testing) are the problematic -f flags:

complete -c rip -n "__fish_use_subcommand" -f -a "completions" -d 'Generate shell completions file'
complete -c rip -n "__fish_use_subcommand" -f -a "graveyard" -d 'Print the graveyard path'
complete -c rip -n "__fish_use_subcommand" -f -a "help" -d 'Print this message or the help of the given subcommand(s)'

Removing those allows files to be included in completion. Here's the author's reply on their usage:

For reference, the completions get generated by clap_complete here:

https://github.com/MilesCranmer/rip2/blob/75ea37ef4ea16ae64809e9c50999d95fd6a809bd/src/completions.rs#L24

I think I'm specifying subcommands correctly here:

https://github.com/MilesCranmer/rip2/blob/75ea37ef4ea16ae64809e9c50999d95fd6a809bd/src/args.rs#L114

epage commented 6 days ago

Not knowing rip2, could you give an example of like

Try completing

$ rip2 something\t

Expected completions:

Actual completions:

If I'm understanding correctly, it sounds like rip2 takes subcommands xor positional arguments and the -f on subcommands is preventing the completion of the positional arguments and hoping a further elaboration like above can clarify the problem.

Mawdac commented 6 days ago

Here's an example of the issue:

touch great.sh
rip gr\t

Expected completions:

great.sh
graveyard

Actual completions

graveyard

Hopefully this is more clear, let me know if I can provide anything further.

epage commented 6 days ago

Thanks!

To fix this, we'll need to check whether positionals are supported in addition to subcommands.

We should ensure a test has this covered in a commit before making the change so that the tests get updated along the way, showing how the behavior changed.