new CLI command brother_ql info version (#34)

This commit is contained in:
Philipp Klaus committed 2018-08-10 11:59:09 +02:00
1 parent a71fc4c09c
commit b59f45fa79
1 file changed
+15 -2
+15 -2
View File
@@ -1,7 +1,7 @@
#!/usr/bin/env python #!/usr/bin/env python
# Python standard library # Python standard library
import logging import logging, sys
# external dependencies # external dependencies
import click import click
@@ -52,7 +52,7 @@ def discover_and_list_available_devices(backend):
print(textual_description_discovered_devices(available_devices)) print(textual_description_discovered_devices(available_devices))
@cli.command() @cli.command()
@click.argument('info', click.Choice(('labels', 'models'))) @click.argument('info', click.Choice(('labels', 'models', 'version')))
@click.pass_context @click.pass_context
def info(ctx, *args, **kwargs): def info(ctx, *args, **kwargs):
""" list available choices (for labels or models) """ """ list available choices (for labels or models) """
@@ -74,6 +74,19 @@ def info(ctx, *args, **kwargs):
from brother_ql.output_helpers import textual_label_description from brother_ql.output_helpers import textual_label_description
print(textual_label_description(label_sizes)) print(textual_label_description(label_sizes))
elif kwargs['info'] == 'version':
"""
Show the version of the package in the form:
``brother_ql VERSION_STRING``
"""
try:
import pkg_resources
version = pkg_resources.get_distribution("brother_ql").version
print("brother_ql %s" % version)
except:
logger.error("Couln't determine the version of the brother_ql package.")
sys.exit(1)
@cli.command('print', short_help='Print a label') @cli.command('print', short_help='Print a label')
@click.argument('images', nargs=-1, metavar='IMAGE [IMAGE] ...') @click.argument('images', nargs=-1, metavar='IMAGE [IMAGE] ...')
@click.option('-l', '--label', type=click.Choice(label_sizes), envvar='BROTHER_QL_LABEL', help='The label (size, type - die-cut or endless). Run `brother_ql info labels` for a full list including ideal pixel dimensions.') @click.option('-l', '--label', type=click.Choice(label_sizes), envvar='BROTHER_QL_LABEL', help='The label (size, type - die-cut or endless). Run `brother_ql info labels` for a full list including ideal pixel dimensions.')