add basic argcomplete support

This commit is contained in:
Patrick Kanzler 2016-07-23 10:00:40 +02:00
parent 457c62cc7f
commit 80b714fdae
No known key found for this signature in database
GPG Key ID: F07F07153306FCEF
2 changed files with 12 additions and 0 deletions

View File

@ -110,6 +110,8 @@ setup(
'six', 'six',
'appdirs', 'appdirs',
'pyyaml', 'pyyaml',
'argparse',
'argcomplete',
], ],
setup_requires=[ setup_requires=[
'setuptools_scm', 'setuptools_scm',

View File

@ -1,4 +1,5 @@
#!/usr/bin/env python #!/usr/bin/env python
# PYTHON_ARGCOMPLETE_OK
""" CLI """ CLI
This module acts as a command line interface for python-escpos. It mirrors This module acts as a command line interface for python-escpos. It mirrors
@ -14,6 +15,11 @@ from __future__ import print_function
from __future__ import unicode_literals from __future__ import unicode_literals
import argparse import argparse
try:
import argcomplete
except ImportError:
# this CLI works nevertheless without argcomplete
pass # noqa
import sys import sys
import six import six
from . import config from . import config
@ -499,6 +505,10 @@ def main():
help='Print the version of python-escpos') help='Print the version of python-escpos')
parser_command_version.set_defaults(version=True) parser_command_version.set_defaults(version=True)
# hook in argcomplete
if 'argcomplete' in globals():
argcomplete.autocomplete(parser)
# Get only arguments actually passed # Get only arguments actually passed
args_dict = vars(parser.parse_args()) args_dict = vars(parser.parse_args())
if not args_dict: if not args_dict: