From 911bc2d2fa989fec57914616ae0ade2c44e0220a Mon Sep 17 00:00:00 2001 From: Andrii Sultanov Date: Tue, 3 Sep 2024 14:38:01 +0100 Subject: [PATCH] xe autocompletion: Exclude previously entered parameters before deciding 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 OPTIONAL: database: REQUIRED: param-name= OPTIONAL: param-key= REQUIRED: uuid= $ xe vm-param-get param-name=SMTH uuid=SMTH <- 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 database: param-key= ``` Signed-off-by: Andrii Sultanov --- ocaml/xe-cli/bash-completion | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/ocaml/xe-cli/bash-completion b/ocaml/xe-cli/bash-completion index 0da9be29c0e..0c29a5446b9 100644 --- a/ocaml/xe-cli/bash-completion +++ b/ocaml/xe-cli/bash-completion @@ -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