diff --git a/README.rst b/README.rst index eb02c6c6..de793127 100644 --- a/README.rst +++ b/README.rst @@ -250,6 +250,19 @@ Terminate a service (all data will be gone!):: Updating service configuration ------------------------------ +Shell completions +----------------- + +avn supports shell completions. It requires an optional dependency: argcomplete. Install it:: + + $ python3 -m pip install argcomplete + +To use completions in bash, add following line to `~/.bashrc`:: + + eval "$(register-python-argcomplete avn)" + +For more information (including completions usage in other shells) see https://kislyuk.github.io/argcomplete/. + More help --------- :: diff --git a/aiven/client/argx.py b/aiven/client/argx.py index fb19cf9a..d7351b4f 100644 --- a/aiven/client/argx.py +++ b/aiven/client/argx.py @@ -15,6 +15,13 @@ import requests.exceptions import sys +# Optional shell completions +try: + import argcomplete # pylint: disable=import-error + ARGCOMPLETE_INSTALLED = True +except ImportError: + ARGCOMPLETE_INSTALLED = False + try: from .version import __version__ # pylint: disable=no-name-in-module except ImportError: @@ -155,6 +162,10 @@ def add_cmds(self, add_func): def parse_args(self, args=None): self.extend_commands(self) + + if ARGCOMPLETE_INSTALLED: + argcomplete.autocomplete(self.parser) + args = self.parser.parse_args(args=args) for ext in self._extensions: ext.args = args diff --git a/scripts/avn b/scripts/avn index c2c4d060..c1fde8d3 100755 --- a/scripts/avn +++ b/scripts/avn @@ -1,4 +1,5 @@ #! /usr/bin/env python3 +# PYTHON_ARGCOMPLETE_OK from aiven.client.cli import AivenCLI AivenCLI().main()