Fix software deploy subcommand completion

This commit fix the current behavior of software bash completion which
was not completing for the software deploy subcommand.

PASS: Software deploy <tab><tab> list all options.
PASS: Software deploy st<tab> completes with 'start'.
PASS: Software deploy start <tab><tab> list flags.

Story: 2010676
Task: 51162

Change-Id: Icfcddbe861a1f0eeb309e3d0e105bdd3989cb768
Signed-off-by: Luis Eduardo Bonatti <luizeduardo.bonatti@windriver.com>
This commit is contained in:
Luis Eduardo Bonatti
2024-10-10 15:30:45 -03:00
parent 8dacb327c9
commit da6fa5d726
2 changed files with 6 additions and 4 deletions

View File

@@ -35,11 +35,11 @@ _software()
kbc="`software deploy bash-completion | sed -e "s/ -h / /"`" kbc="`software deploy bash-completion | sed -e "s/ -h / /"`"
_software_deploy_opts="`echo "$kbc" | sed -e "s/--[a-z0-9_-]*//g" -e "s/[ ][ ]*/ /g"`" _software_deploy_opts="`echo "$kbc" | sed -e "s/--[a-z0-9_-]*//g" -e "s/[ ][ ]*/ /g"`"
_software_deploy_flags="`echo " $kbc" | sed -e "s/ [^-][^-][a-z0-9_-]*//g" -e "s/[ ][ ]*/ /g"`" _software_deploy_flags="`echo " $kbc" | sed -e "s/ [^-][^-][a-z0-9_-]*//g" -e "s/[ ][ ]*/ /g"`"
_software_deploy_opts_exp="`echo $_software_deploy_opts | sed -e "s/[ ]/|/g"`" _software_deploy_opts_exp="`echo $_software_deploy_opts | sed -e "s/[ ]\+/|/g"`"
fi fi
if [ "$cmd" == "deploy" ] ; then if [ "$cmd" == "deploy" ] ; then
if [[ " ${COMP_WORDS[@]} " =~ " "$_software_deploy_opts_exp" " && "$prev" != "help" ]] ; then if [[ " ${_software_deploy_opts} " == *" $prev "* && "$prev" != "help" ]] ; then
COMPREPLY=($(compgen -W "${_software_deploy_flags}" -- ${cur})) COMPREPLY=($(compgen -W "${_software_deploy_flags}" -- ${cur}))
else else
COMPREPLY=($(compgen -W "${_software_deploy_opts}" -- ${cur})) COMPREPLY=($(compgen -W "${_software_deploy_opts}" -- ${cur}))

View File

@@ -405,14 +405,16 @@ class SoftwareClientShell(object):
deploy_options = set() deploy_options = set()
software_deploy_command = "software deploy" software_deploy_command = "software deploy"
deploy_command = "deploy" deploy_command = "deploy"
unlisted_commands = [deploy_command, "bash-completion", "bash_completion"] unlisted_commands = ["bash-completion", "bash_completion"]
for sc_str, sc in self.subcommands.items(): for sc_str, sc in self.subcommands.items():
# Separate between software command and deploy commands # Separate between software command and deploy commands
if sc.prog.startswith(software_deploy_command): if sc.prog.startswith(software_deploy_command):
if sc_str in unlisted_commands: if sc_str in unlisted_commands:
continue continue
deploy_commands.add(sc_str) # Remove deploy prefix output
opt = sc_str[len(f"{deploy_command} "):]
deploy_commands.add(opt)
for option in list(sc._optionals._option_string_actions): for option in list(sc._optionals._option_string_actions):
deploy_options.add(option) deploy_options.add(option)
else: else: