Skip to content

Commit

Permalink
xe autocompletion: Exclude previously entered parameters before deciding
Browse files Browse the repository at this point in the history
whether to show optionality of the parameters

Fixes the bug when optionality of parameters would be shown when all the
remaining parameters were of the same category, autocompleting the noise:
```
$ xe vm-param-get <TAB>
OPTIONAL: database:    REQUIRED: param-name=
OPTIONAL: param-key=   REQUIRED: uuid=

$ xe vm-param-get param-name=SMTH uuid=SMTH <TAB> <- automatically completes to
$ xe vm-param-get param-name=SMTH uuid=SMTH OPTIONAL:
```

Now works as intended:
```
$ xe vm-param-get param-name=SMTH uuid=SMTH <TAB>
database:   param-key=
```

Signed-off-by: Andrii Sultanov <[email protected]>
  • Loading branch information
last-genius committed Sep 3, 2024
1 parent 0ac2b0b commit 911bc2d
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions ocaml/xe-cli/bash-completion
Original file line number Diff line number Diff line change
Expand Up @@ -814,15 +814,14 @@ set_completions()
if [[ $REQD_OPTIONAL_PARAMS == 1 ]]; then
local reqd_params=$( __preprocess_suggestions "$REQD_PARAMS" )
local opt_params=$( __preprocess_suggestions "$OPT_PARAMS" )
if [[ "$excludes" ]]; then
reqd_params=$(echo "$reqd_params" | eval "grep -v $excludes")
opt_params=$(echo "$opt_params" | eval "grep -v $excludes")
fi
if [[ "$reqd_params" && "$opt_params" ]]; then
__xe_debug "showing optional/required parameters"
SHOW_DESCRIPTION=1

if [[ "$excludes" ]]; then
reqd_params=$(echo "$reqd_params" | eval "grep -v $excludes")
opt_params=$(echo "$opt_params" | eval "grep -v $excludes")
fi

for word in $reqd_params; do
__add_completion "$word" "REQUIRED" "$max_cmd_length"
done
Expand Down

0 comments on commit 911bc2d

Please sign in to comment.