Skip to content

Commit

Permalink
Merge pull request #139 from aiven/rominf-shell-completions
Browse files Browse the repository at this point in the history
Add optional shell completions

#139
  • Loading branch information
Ormod authored Apr 20, 2020
2 parents 9e59335 + 27e6414 commit 168be68
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
13 changes: 13 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
---------
::
Expand Down
11 changes: 11 additions & 0 deletions aiven/client/argx.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions scripts/avn
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#! /usr/bin/env python3
# PYTHON_ARGCOMPLETE_OK
from aiven.client.cli import AivenCLI

AivenCLI().main()

0 comments on commit 168be68

Please sign in to comment.