Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support fish correct completion for nested subcommands #2715

Closed
2 tasks done
ModProg opened this issue Aug 18, 2021 · 4 comments
Closed
2 tasks done

Support fish correct completion for nested subcommands #2715

ModProg opened this issue Aug 18, 2021 · 4 comments
Labels
A-completion Area: completion generator C-bug Category: Updating dependencies

Comments

@ModProg
Copy link
Contributor

ModProg commented Aug 18, 2021

Please complete the following tasks

  • I have searched the discussions
  • I have searched the existing issues

Clap Version

master

Describe your use case

There are two cases where the current solution does not work:

Simple case (can be solved with fish build-ins)

Example command syntax:
command A B <parameter>
command A C <parameter>
Currently pressing tab after writing A it will complete B as well as C again.

Complex case (we probably would need to write something our own)

Probably wont happen that often:
Two subcommand chains:
command A B C
command B A D
These are even with the simple solution not differentiable.

Describe the solution you'd like

Simple Case

Instead of only requirering the parent subcommand to exist, rather also check that self and the sibling commands do not exist:

complete -c command -n "__fish_use_subcommand" -x -a "A"
complete -c command -n "__fish_seen_subcommand_from A; and not __fish_seen_subcommand_from B C" -x -a "B"
complete -c command -n "__fish_seen_subcommand_from A; and not __fish_seen_subcommand_from B C" -x -a "C"

Complex case

Not sure how to solve. Probably need something like

clap/src/completions.rs

Lines 237 to 248 in a61eaf8

r#"function __fish_using_command
set cmd (commandline -opc)
if [ (count $cmd) -eq (count $argv) ]
for i in (seq (count $argv))
if [ $cmd[$i] != $argv[$i] ]
return 1
end
end
return 0
end
return 1
end
again.
With fish buildins A B and B A is the same. Therefor you would get both C and D for both. The same would happen if at some point a subcommand gets repeated (maybe more likely than the AB BA example).

Insufficient solution using standard complete functionality

complete -c command -n "__fish_use_subcommand" -x -a "A"
complete -c command -n "__fish_use_subcommand" -x -a "B"
complete -c command -n "__fish_seen_subcommand_from A; and not __fish_seen_subcommand_from B" -x -a "B"
complete -c command -n "__fish_seen_subcommand_from B; and not __fish_seen_subcommand_from A" -x -a "A"
complete -c command -n "__fish_seen_subcommand_from A; and __fish_seen_subcommand_from B;  and not __fish_seen_subcommand_from C" -x -a "C"
complete -c command -n "__fish_seen_subcommand_from B; and __fish_seen_subcommand_from A;  and not __fish_seen_subcommand_from D" -x -a "D"

Alternatives, if applicable

No response

Additional Context

This is somewhat a regression see #685

@ModProg
Copy link
Contributor Author

ModProg commented Aug 18, 2021

Hmm, maybe this would have been rather a bug than a feature

@pksunkara
Copy link
Member

I wouldn't worry about subcommand chains since they are not supported in clap.

@pksunkara pksunkara added C-bug Category: Updating dependencies A-completion Area: completion generator and removed T: new feature labels Aug 18, 2021
@ModProg
Copy link
Contributor Author

ModProg commented Aug 18, 2021

I wouldn't worry about subcommand chains since they are not supported in clap.

I did not mean chained commands, I meant multiple level of subcommands, where the naming is repeating.

@ModProg
Copy link
Contributor Author

ModProg commented Aug 18, 2021

I'll have a look at how the simple version can be implemented.

ModProg added a commit to ModProg/clap that referenced this issue Aug 19, 2021
* Prevent completing subcommands that were already completed

* Make sure all parent subcommands actually existent

Partially fixes clap-rs#2715
ModProg added a commit to ModProg/clap that referenced this issue Aug 19, 2021
* Prevent completing subcommands that were already completed

* Make sure all parent subcommands actually existent

Partially fixes clap-rs#2715
ModProg added a commit to ModProg/clap that referenced this issue Aug 20, 2021
* Prevent completing subcommands that were already completed

* Make sure all parent subcommands actually existent

Partially fixes clap-rs#2715
ModProg added a commit to ModProg/clap that referenced this issue Aug 20, 2021
* Prevent completing subcommands that were already completed

* Make sure all parent subcommands actually existent

Partially fixes clap-rs#2715
ModProg added a commit to ModProg/clap that referenced this issue Aug 20, 2021
* Prevent completing subcommands that were already completed

* Make sure all parent subcommands actually existent

Partially fixes clap-rs#2715
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-completion Area: completion generator C-bug Category: Updating dependencies
Projects
None yet
Development

No branches or pull requests

2 participants