Skip to content

Commit

Permalink
picocli fish completion: fixed root options
Browse files Browse the repository at this point in the history
  • Loading branch information
serg-v committed Feb 25, 2023
1 parent 1b90553 commit 2f75728
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
1 change: 1 addition & 0 deletions src/main/java/picocli/AutoComplete.java
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,7 @@ public static String fish(String scriptName, CommandLine commandLine) {
for (CommandDescriptor descriptor : hierarchy) {
if (descriptor.parentFunctionName.equals("")) {
rootDescriptor = descriptor;
parentFunction = descriptor.functionName;
continue;
}
if (!descriptor.parentFunctionName.equals(parentFunction)) {
Expand Down
8 changes: 4 additions & 4 deletions src/test/dejagnu.fishtests/completion/picocompletion-demo.exp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ run_completion_test $cmd $test $candidates
# set test "Tab should not show completions for '${cmd}'"

# there is completion from root level
# set cmd "picocompletion-demo sub1 -"
# set test "Tab should show sub1 options for '${cmd}'"
# set candidates "-h --candidates --candidates= (with candidates) --num (a number) --version"
# run_completion_test $cmd $test $candidates
set cmd "picocompletion-demo sub1 -"
set test "Tab should show sub1 options for '${cmd}'"
set candidates "--candidates.*--candidates=.*--num.*--str.*"
run_completion_test $cmd $test $candidates
7 changes: 2 additions & 5 deletions src/test/resources/picocompletion-demo_completion.fish
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@

# root completion
set -l root
complete -c picocompletion-demo --condition "not __fish_seen_subcommand_from $root" --long-option version --short-option V -d ''
complete -c picocompletion-demo --condition "not __fish_seen_subcommand_from $root" --long-option help --short-option h -d ''

# _picocli_picocompletion_demo completion
set -l _picocli_picocompletion_demo sub1 sub1-alias sub2 sub2-alias
complete -c picocompletion-demo --condition "not __fish_seen_subcommand_from $_picocli_picocompletion_demo" --long-option version --short-option V -d ''
complete -c picocompletion-demo --condition "not __fish_seen_subcommand_from $_picocli_picocompletion_demo" --long-option help --short-option h -d ''
complete -c picocompletion-demo --no-files --condition "not __fish_seen_subcommand_from $_picocli_picocompletion_demo" --arguments sub1 -d 'First level subcommand 1'
complete -c picocompletion-demo --condition "__fish_seen_subcommand_from sub1" --long-option num -d 'a number'
complete -c picocompletion-demo --condition "__fish_seen_subcommand_from sub1" --long-option str -d 'a String'
Expand Down

0 comments on commit 2f75728

Please sign in to comment.