Skip to content

Commit

Permalink
Client will install bash completion file.
Browse files Browse the repository at this point in the history
JIRA: PDC-1161
  • Loading branch information
zkl94 committed Nov 13, 2015
1 parent 05280ef commit d9e811d
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 17 deletions.
6 changes: 6 additions & 0 deletions docs/source/pdc_client.rst
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ requests manually.
This is much more user friendly user interface. A single invocation can perform
multiple requests depending on what subcommand you used.

Although auto-completion is inherently enabled for pdc, it will be disabled if
`python-argcomplete` is not installed. To enable it, install `python-argcomplete`
and activate by typing `activate-global-python-argcomplete` in command line.
Please note that by doing this only global completion is enabled which is
currently not compatible with zsh.


Python API
----------
Expand Down
3 changes: 3 additions & 0 deletions pdc_client/pdc-client.spec
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,15 @@ install -m 0644 -D -p bin/pdc %{buildroot}%{_bindir}/pdc
install -m 0644 -D -p docs/pdc_client.1 %{buildroot}%{_mandir}/man1/pdc_client.1
gzip %{buildroot}%{_mandir}/man1/pdc_client.1

# Install pdc bash completion file
install -m 0644 -D -p pdc_bash_completion %{buildroot}%{_sysconfdir}/bash_completion.d/pdc

%files
%{python_sitelib}/pdc_client
%attr(755, root, root) %{_bindir}/pdc_client
%attr(755, root, root) %{_bindir}/pdc
%{_mandir}/man1/pdc_client.1.gz
%{_sysconfdir}/bash_completion.d/pdc


%changelog
Expand Down
8 changes: 8 additions & 0 deletions pdc_client/pdc_bash_completion
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
_python_argcomplete() {
local IFS=' '
COMPREPLY=( $(IFS="$IFS" COMP_LINE="$COMP_LINE" COMP_POINT="$COMP_POINT" _ARGCOMPLETE_COMP_WORDBREAKS="$COMP_WORDBREAKS" _ARGCOMPLETE=1 "$1" 8>&1 9>&2 1>/dev/null 2>/dev/null) )
if [[ $? != 0 ]]; then
unset COMPREPLY
fi
}
complete -o nospace -o default -F _python_argcomplete "pdc"
18 changes: 1 addition & 17 deletions pdc_client/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,7 @@
import logging
import imp

# The client supports Bash completion if argcomplete Python package is
# installed. To enable it, run this in your terminal (assuming pdc is somewhere
# on path).
#
# eval "$(register-python-argcomplete pdc)"
#
# This is only a temporary solution, when the client is packaged, a completion
# file should be shipped with it and installed to /etc/bash_completion.d/.
try:
import argcomplete
except ImportError:
class argcomplete(object):
@classmethod
def autocomplete(*args):
pass
# The client supports Bash completion if argcomplete Python package is installed.

import pdc_client

Expand Down Expand Up @@ -86,8 +72,6 @@ def setup(self):
plugin._before_register(subparsers)
plugin.register()

argcomplete.autocomplete(self.parser)

def run(self, args=None):
self.args = self.parser.parse_args(args=args)
self.client = pdc_client.PDCClient(self.args.server)
Expand Down

0 comments on commit d9e811d

Please sign in to comment.