From 7f28027bfed76a7d2205c7efa42c0f41b9b9aacd Mon Sep 17 00:00:00 2001 From: Philipp Klaus Date: Mon, 3 Sep 2018 16:50:23 +0200 Subject: [PATCH] Make `brother_ql info` a click.group() --- README.md | 2 +- brother_ql/cli.py | 118 +++++++++++++++++++++++----------------------- 2 files changed, 61 insertions(+), 59 deletions(-) diff --git a/README.md b/README.md index e7d5b47..bd342e9 100644 --- a/README.md +++ b/README.md @@ -82,7 +82,7 @@ The main user interface of this package is the command line tool `brother_ql`. Commands: analyze interpret a binary file containing raster... discover find connected label printers - info list available choices (for labels or models) + info list available labels, models etc. print Print a label send send an instruction file to the printer diff --git a/brother_ql/cli.py b/brother_ql/cli.py index 3c633ce..17bc584 100755 --- a/brother_ql/cli.py +++ b/brother_ql/cli.py @@ -53,69 +53,71 @@ def discover_and_list_available_devices(backend): log_discovered_devices(available_devices) print(textual_description_discovered_devices(available_devices)) -@cli.command() -@click.argument('info', click.Choice(('labels', 'models', 'env'))) +@cli.group() @click.pass_context def info(ctx, *args, **kwargs): - """ list available choices (for labels or models) """ - if kwargs['info'] == 'models': - """List the models (choices for --model) - - List the models that can be used with this software. - Those are the choices avaiable for the --model option. - """ - print('Supported models:') - for model in models: print(" " + model) + """ list available labels, models etc. """ - elif kwargs['info'] == 'labels': - """ - List labels (types and sizes). +@info.command(name='models') +@click.pass_context +def models_cmd(ctx, *args, **kwargs): + """ + List the choices for --model + """ + print('Supported models:') + for model in models: print(" " + model) - This command lists all labels (label types and label sizes) - that can be used with this software. """ - from brother_ql.output_helpers import textual_label_description - print(textual_label_description(label_sizes)) +@info.command() +@click.pass_context +def labels(ctx, *args, **kwargs): + """ + List the choices for --label + """ + from brother_ql.output_helpers import textual_label_description + print(textual_label_description(label_sizes)) - elif kwargs['info'] == 'env': - """ - Print information about the running environment of brother_ql. - """ - import sys, platform, os, shutil - from pkg_resources import get_distribution, working_set - print("\n##################\n") - print("Information about the running environment of brother_ql.") - print("(Please provide this information when reporting any issue.)\n") - # computer - print("About the computer:") - for attr in ('platform', 'processor', 'release', 'system', 'machine', 'architecture'): - print(' * '+attr.title()+':', getattr(platform, attr)()) - # Python - print("About the installed Python version:") - py_version = str(sys.version).replace('\n', ' ') - print(" *", py_version) - # brother_ql - print("About the brother_ql package:") - pkg = get_distribution('brother_ql') - print(" * package location:", pkg.location) - print(" * package version: ", pkg.version) - try: - cli_loc = shutil.which('brother_ql') - except: - cli_loc = 'unknown' - print(" * brother_ql CLI path:", cli_loc) - # brother_ql's requirements - print("About the requirements of brother_ql:") - fmt = " {req:14s} | {spec:10s} | {ins_vers:17s}" - print(fmt.format(req='requirement', spec='requested', ins_vers='installed version')) - print(fmt.format(req='-' * 14, spec='-'*10, ins_vers='-'*17)) - requirements = list(pkg.requires()) - requirements.sort(key=lambda x: x.project_name) - for req in requirements: - proj = req.project_name - req_pkg = get_distribution(proj) - spec = ' '.join(req.specs[0]) if req.specs else 'any' - print(fmt.format(req=proj, spec=spec, ins_vers=req_pkg.version)) - print("\n##################\n") +@info.command() +@click.pass_context +def env(ctx, *args, **kwargs): + """ + print debug info about running environment + """ + import sys, platform, os, shutil + from pkg_resources import get_distribution, working_set + print("\n##################\n") + print("Information about the running environment of brother_ql.") + print("(Please provide this information when reporting any issue.)\n") + # computer + print("About the computer:") + for attr in ('platform', 'processor', 'release', 'system', 'machine', 'architecture'): + print(' * '+attr.title()+':', getattr(platform, attr)()) + # Python + print("About the installed Python version:") + py_version = str(sys.version).replace('\n', ' ') + print(" *", py_version) + # brother_ql + print("About the brother_ql package:") + pkg = get_distribution('brother_ql') + print(" * package location:", pkg.location) + print(" * package version: ", pkg.version) + try: + cli_loc = shutil.which('brother_ql') + except: + cli_loc = 'unknown' + print(" * brother_ql CLI path:", cli_loc) + # brother_ql's requirements + print("About the requirements of brother_ql:") + fmt = " {req:14s} | {spec:10s} | {ins_vers:17s}" + print(fmt.format(req='requirement', spec='requested', ins_vers='installed version')) + print(fmt.format(req='-' * 14, spec='-'*10, ins_vers='-'*17)) + requirements = list(pkg.requires()) + requirements.sort(key=lambda x: x.project_name) + for req in requirements: + proj = req.project_name + req_pkg = get_distribution(proj) + spec = ' '.join(req.specs[0]) if req.specs else 'any' + print(fmt.format(req=proj, spec=spec, ins_vers=req_pkg.version)) + print("\n##################\n") @cli.command('print', short_help='Print a label') @click.argument('images', nargs=-1, metavar='IMAGE [IMAGE] ...')