diff --git a/software/debian/deb_folder/control b/software/debian/deb_folder/control index a91ced9b..7ab373d6 100644 --- a/software/debian/deb_folder/control +++ b/software/debian/deb_folder/control @@ -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. diff --git a/software/requirements.txt b/software/requirements.txt index 189637ed..6f17b256 100644 --- a/software/requirements.txt +++ b/software/requirements.txt @@ -1,3 +1,4 @@ +argcomplete keystoneauth1 keystonemiddleware lxml diff --git a/software/service-files/software.completion b/software/service-files/software.completion index a935c5f0..79ffbe06 100644 --- a/software/service-files/software.completion +++ b/software/service-files/software.completion @@ -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)" diff --git a/software/setup.py b/software/setup.py index 4e042b36..328c6ee5 100644 --- a/software/setup.py +++ b/software/setup.py @@ -6,4 +6,3 @@ import setuptools setuptools.setup() - diff --git a/software/software/software_client.py b/software/software/software_client.py index edb6e65a..5a7b41f5 100644 --- a/software/software/software_client.py +++ b/software/software/software_client.py @@ -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)