Bash completion for USM
This commit enables bash completion for Unified Software Management commands using argcomplete module. Test Plan: [PASS] Build and install the iso [PASS] Test bash completion for software commands Story: 2010676 Task: 48540 Depends-On: https://review.opendev.org/c/888955 Signed-off-by: Jessica Castelino <jessica.castelino@windriver.com> Change-Id: Id1d404ff48029c61040f2f137b0169d5ac6919d6
This commit is contained in:
parent
e8c8b24922
commit
f29561900f
@ -18,7 +18,8 @@ Package: software
|
||||
Architecture: all
|
||||
Depends: ${python3:Depends},
|
||||
${misc:Depends},
|
||||
gir1.2-ostree-1.0
|
||||
gir1.2-ostree-1.0,
|
||||
python3-argcomplete
|
||||
Description: StarlingX unified software deployment and management
|
||||
StarlingX unified software deployment and management.
|
||||
|
||||
|
@ -1,3 +1,4 @@
|
||||
argcomplete
|
||||
keystoneauth1
|
||||
keystonemiddleware
|
||||
lxml
|
||||
|
@ -9,145 +9,4 @@
|
||||
# the unified software management CLI
|
||||
#
|
||||
|
||||
function _sw()
|
||||
{
|
||||
COMPREPLY=()
|
||||
local cur="${COMP_WORDS[COMP_CWORD]}"
|
||||
local prev="${COMP_WORDS[COMP_CWORD-1]}"
|
||||
local subcommand=${COMP_WORDS[1]}
|
||||
|
||||
#
|
||||
# The available software subcommands
|
||||
#
|
||||
local subcommands="
|
||||
release upload
|
||||
release upload-dir
|
||||
release delete
|
||||
release list
|
||||
release show
|
||||
deploy create
|
||||
deploy list
|
||||
deploy precheck
|
||||
deploy start
|
||||
deploy host
|
||||
deploy query
|
||||
deploy activate
|
||||
deploy complete
|
||||
deploy abort
|
||||
deploy host-rollback
|
||||
is-applied
|
||||
is-available
|
||||
report-app-dependencies
|
||||
query-app-dependencies
|
||||
what-requires
|
||||
"
|
||||
if [ -f /etc/platform/.initial_config_complete ]; then
|
||||
# Post-config, so the host-install commands are accessible
|
||||
subcommands="${subcommands} deploy host"
|
||||
else
|
||||
# Pre-config, so the install-local command is accessible
|
||||
subcommands="${subcommands} install-local"
|
||||
fi
|
||||
|
||||
# Appends the '/' when completing dir names
|
||||
set mark-directories on
|
||||
|
||||
if [ $COMP_CWORD -gt 1 ]; then
|
||||
#
|
||||
# Complete the arguments to the subcommands.
|
||||
#
|
||||
case "$subcommand" in
|
||||
apply|delete|show|what-requires|is-applied|is-available)
|
||||
# Query the list of known patches
|
||||
local patches=$(software completion patches 2>/dev/null)
|
||||
COMPREPLY=( $(compgen -W "${patches}" -- ${cur}) )
|
||||
return 0
|
||||
;;
|
||||
remove)
|
||||
# Query the list of known patches
|
||||
local patches=$(software completion patches 2>/dev/null)
|
||||
COMPREPLY=( $(compgen -W "--skipappcheck ${patches}" -- ${cur}) )
|
||||
return 0
|
||||
;;
|
||||
host-install|host-install-async|drop-host)
|
||||
if [ "${prev}" = "${subcommand}" -o "${prev}" = "--force" ]; then
|
||||
# Query the list of known hosts
|
||||
local names=$(software completion hosts 2>/dev/null)
|
||||
COMPREPLY=( $(compgen -W "${names}" -- ${cur}) )
|
||||
else
|
||||
# Only one host can be specified, so no more completion
|
||||
COMPREPLY=( $(compgen -- ${cur}) )
|
||||
fi
|
||||
return 0
|
||||
;;
|
||||
upload)
|
||||
# Allow dirs and files with .patch extension for completion
|
||||
COMPREPLY=( $(compgen -f -o plusdirs -X '!*.patch' -- ${cur}) )
|
||||
return 0
|
||||
;;
|
||||
upload-dir)
|
||||
# Allow dirs only for completion
|
||||
COMPREPLY=( $(compgen -d -- ${cur}) )
|
||||
return 0
|
||||
;;
|
||||
query)
|
||||
if [ "${prev}" = "--release" ]; then
|
||||
# If --release has been specified, provide installed releases for completion
|
||||
local releases=$(/bin/ls -d /var/www/pages/feed/rel-* 2>/dev/null | sed 's#/var/www/pages/feed/rel-##')
|
||||
COMPREPLY=( $(compgen -W "${releases}" -- ${cur}) )
|
||||
else
|
||||
# --release is only completion option for query
|
||||
COMPREPLY=( $(compgen -W "--release" -- ${cur}) )
|
||||
fi
|
||||
return 0
|
||||
;;
|
||||
query-hosts|install-local)
|
||||
# These subcommands have no options/arguments
|
||||
COMPREPLY=( $(compgen -- ${cur}) )
|
||||
return 0
|
||||
;;
|
||||
query-dependencies)
|
||||
# Query the list of known patches
|
||||
local patches=$(software completion patches 2>/dev/null)
|
||||
COMPREPLY=( $(compgen -W "--recursive ${patches}" -- ${cur}) )
|
||||
return 0
|
||||
;;
|
||||
commit)
|
||||
if [ "${prev}" = "--release" ]; then
|
||||
# If --release has been specified, provide installed releases for completion
|
||||
local releases=$(/bin/ls -d /var/www/pages/feed/rel-* 2>/dev/null | sed 's#/var/www/pages/feed/rel-##')
|
||||
COMPREPLY=( $(compgen -W "${releases}" -- ${cur}) )
|
||||
else
|
||||
# Query the list of known patches
|
||||
local patches=$(software completion patches 2>/dev/null)
|
||||
COMPREPLY=( $(compgen -W "--all --dry-run --release ${patches}" -- ${cur}) )
|
||||
fi
|
||||
return 0
|
||||
;;
|
||||
report-app-dependencies)
|
||||
if [ "${prev}" = "${subcommand}" ]; then
|
||||
COMPREPLY=( $(compgen -W "--app" -- ${cur}) )
|
||||
elif [ "${prev}" = "--app" ]; then
|
||||
COMPREPLY=
|
||||
else
|
||||
local patches=$(software completion patches 2>/dev/null)
|
||||
COMPREPLY=( $(compgen -W "${patches}" -- ${cur}) )
|
||||
fi
|
||||
return 0
|
||||
;;
|
||||
query-app-dependencies)
|
||||
return 0
|
||||
;;
|
||||
*)
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
|
||||
# Provide subcommands for completion
|
||||
COMPREPLY=($(compgen -W "${subcommands}" -- ${cur}))
|
||||
return 0
|
||||
}
|
||||
|
||||
# Bind the above function to the software CLI
|
||||
complete -F _sw -o filenames software
|
||||
|
||||
eval "$(register-python-argcomplete3 software)"
|
||||
|
@ -6,4 +6,3 @@
|
||||
import setuptools
|
||||
|
||||
setuptools.setup()
|
||||
|
||||
|
@ -4,6 +4,8 @@ Copyright (c) 2023 Wind River Systems, Inc.
|
||||
SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
"""
|
||||
# PYTHON_ARGCOMPLETE_OK
|
||||
import argcomplete
|
||||
import argparse
|
||||
import json
|
||||
import os
|
||||
@ -1307,6 +1309,7 @@ def main():
|
||||
|
||||
rc = 0
|
||||
parser = setup_argparse()
|
||||
argcomplete.autocomplete(parser)
|
||||
args = parser.parse_args()
|
||||
dc_request = check_for_os_region_name(args)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user