From b62e1f6986e3bd5301944151e07509166eb324f0 Mon Sep 17 00:00:00 2001 From: taleksovska Date: Thu, 14 Mar 2024 16:49:50 +0100 Subject: [PATCH 1/3] Add auto-complete for all commands of enabler --- enabler/enabler_autocomplete.py | 63 +++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100755 enabler/enabler_autocomplete.py diff --git a/enabler/enabler_autocomplete.py b/enabler/enabler_autocomplete.py new file mode 100755 index 0000000..7a071be --- /dev/null +++ b/enabler/enabler_autocomplete.py @@ -0,0 +1,63 @@ +#!/usr/bin/env python +import argcomplete +import argparse + +def apps_namespace_subparser(subparsers): + parser = subparsers.add_parser('apps') + parser.add_argument('namespace') + +def platform_subparser(subparsers): + parser = subparsers.add_parser('platform') + subsubparsers = parser.add_subparsers(dest='platform_command') + subsubparsers.required = True + + subparser_init = subsubparsers.add_parser('init') + subparser_info = subsubparsers.add_parser('info') + subparser_keys = subsubparsers.add_parser('keys') + subparser_release = subsubparsers.add_parser('release') + subparser_version = subsubparsers.add_parser('version') + +def kind_subparser(subparsers): + parser = subparsers.add_parser('kind') + subsubparsers = parser.add_subparsers(dest='kind_command') + subsubparsers.required = True + + subparser_create = subsubparsers.add_parser('create') + subparser_delete = subsubparsers.add_parser('delete') + subparser_status = subsubparsers.add_parser('status') + subparser_start = subsubparsers.add_parser('start') + subparser_stop = subsubparsers.add_parser('stop') + +def setup_subparser(subparsers): + parser = subparsers.add_parser('setup') + subsubparsers = parser.add_subparsers(dest='setup_command') + subsubparsers.required = True + + subparser_init = subsubparsers.add_parser('init') + subparser_metallb = subsubparsers.add_parser('metallb') + subparser_istio = subsubparsers.add_parser('istio') + +def version_subparser(subparsers): + subparsers.add_parser('version') + +def preflight_subparser(subparsers): + subparsers.add_parser('preflight') + +def main(): + parser = argparse.ArgumentParser() + subparsers = parser.add_subparsers(dest='command') + subparsers.required = True + + apps_namespace_subparser(subparsers) + platform_subparser(subparsers) + kind_subparser(subparsers) + setup_subparser(subparsers) + version_subparser(subparsers) + preflight_subparser(subparsers) + + argcomplete.autocomplete(parser) + args = parser.parse_args() + + + +main() \ No newline at end of file From 3db356a2e8c647f8eca5ab2beaac76ad8468cc79 Mon Sep 17 00:00:00 2001 From: taleksovska Date: Fri, 15 Mar 2024 16:30:34 +0100 Subject: [PATCH 2/3] Add auto-complete for all commands of enabler --- enabler/enabler_autocomplete.py | 41 +++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/enabler/enabler_autocomplete.py b/enabler/enabler_autocomplete.py index 7a071be..2139513 100755 --- a/enabler/enabler_autocomplete.py +++ b/enabler/enabler_autocomplete.py @@ -2,47 +2,54 @@ import argcomplete import argparse + def apps_namespace_subparser(subparsers): parser = subparsers.add_parser('apps') parser.add_argument('namespace') + def platform_subparser(subparsers): parser = subparsers.add_parser('platform') subsubparsers = parser.add_subparsers(dest='platform_command') subsubparsers.required = True - subparser_init = subsubparsers.add_parser('init') - subparser_info = subsubparsers.add_parser('info') - subparser_keys = subsubparsers.add_parser('keys') - subparser_release = subsubparsers.add_parser('release') - subparser_version = subsubparsers.add_parser('version') + subparser_init = subsubparsers.add_parser('init') # noqa + subparser_info = subsubparsers.add_parser('info') # noqa + subparser_keys = subsubparsers.add_parser('keys') # noqa + subparser_release = subsubparsers.add_parser('release') # noqa + subparser_version = subsubparsers.add_parser('version') # noqa + def kind_subparser(subparsers): parser = subparsers.add_parser('kind') subsubparsers = parser.add_subparsers(dest='kind_command') subsubparsers.required = True - subparser_create = subsubparsers.add_parser('create') - subparser_delete = subsubparsers.add_parser('delete') - subparser_status = subsubparsers.add_parser('status') - subparser_start = subsubparsers.add_parser('start') - subparser_stop = subsubparsers.add_parser('stop') + subparser_create = subsubparsers.add_parser('create') # noqa + subparser_delete = subsubparsers.add_parser('delete') # noqa + subparser_status = subsubparsers.add_parser('status') # noqa + subparser_start = subsubparsers.add_parser('start') # noqa + subparser_stop = subsubparsers.add_parser('stop') # noqa + def setup_subparser(subparsers): parser = subparsers.add_parser('setup') subsubparsers = parser.add_subparsers(dest='setup_command') subsubparsers.required = True - subparser_init = subsubparsers.add_parser('init') - subparser_metallb = subsubparsers.add_parser('metallb') - subparser_istio = subsubparsers.add_parser('istio') + subparser_init = subsubparsers.add_parser('init') # noqa + subparser_metallb = subsubparsers.add_parser('metallb') # noqa + subparser_istio = subsubparsers.add_parser('istio') # noqa + def version_subparser(subparsers): subparsers.add_parser('version') + def preflight_subparser(subparsers): subparsers.add_parser('preflight') + def main(): parser = argparse.ArgumentParser() subparsers = parser.add_subparsers(dest='command') @@ -55,9 +62,9 @@ def main(): version_subparser(subparsers) preflight_subparser(subparsers) - argcomplete.autocomplete(parser) - args = parser.parse_args() - + argcomplete.autocomplete(parser, exclude=[None]) # Modify this line + args = parser.parse_args() # noqa -main() \ No newline at end of file +if __name__ == "__main__": + main() From e16bd69b1d7f347902110e29467681531af52694 Mon Sep 17 00:00:00 2001 From: taleksovska Date: Tue, 19 Mar 2024 09:40:47 +0100 Subject: [PATCH 3/3] Improve autocompletion functionality for 'enabler' command --- enabler/commands/enabler_completion.sh | 55 ++++++++++++++++++++ enabler/enabler_autocomplete.py | 70 -------------------------- 2 files changed, 55 insertions(+), 70 deletions(-) create mode 100755 enabler/commands/enabler_completion.sh delete mode 100755 enabler/enabler_autocomplete.py diff --git a/enabler/commands/enabler_completion.sh b/enabler/commands/enabler_completion.sh new file mode 100755 index 0000000..b761d59 --- /dev/null +++ b/enabler/commands/enabler_completion.sh @@ -0,0 +1,55 @@ +_enabler_complete() { + local cur_word prev_word commands + + # Get the current and previous words + cur_word="${COMP_WORDS[COMP_CWORD]}" + prev_word="${COMP_WORDS[COMP_CWORD-1]}" + local categories="apps kind preflight platform setup version" + + case "$prev_word" in + "enabler") # noqa + commands="$categories" + ;; + esac + + # Initialize the variable to store previous words + prev_words="" + local apps="namespace" + local kind="create delete status start stop" + local platform="init info keys release version" + local setup="init metallb istio" + + # Loop through previous words and concatenate them + for ((i=1; i