From 5ef9873ebefd144b2e91cac0f45c7b2361b4d71b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20Elio=20Petten=C3=B2?= Date: Mon, 17 Apr 2017 16:47:58 +0100 Subject: Add support for a "help" action that prints the driver module's docstring. This allows the drivers to provide information on what they support directly, rather than relying on the README file. It also allows to provide further information for the quirkier devices. This is again trying to resolve Issue #9. --- glucometer.py | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'glucometer.py') diff --git a/glucometer.py b/glucometer.py index dc5d78b..19a47a8 100755 --- a/glucometer.py +++ b/glucometer.py @@ -9,6 +9,7 @@ __license__ = 'MIT' import argparse import importlib +import inspect import logging import sys @@ -34,6 +35,9 @@ def main(): help=('Python logging level. See the levels at ' 'https://docs.python.org/3/library/logging.html#logging-levels')) + subparsers.add_parser( + 'help', help=('Display a description of the driver, including supported ' + 'features and known quirks.')) subparsers.add_parser( 'info', help='Display information about the meter.') subparsers.add_parser( @@ -67,6 +71,12 @@ def main(): args.driver) return 1 + # This check needs to happen before we try to initialize the device, as the + # help action does not require a --device at all. + if args.action == 'help': + print(inspect.getdoc(driver)) + return 0 + device = driver.Device(args.device) device.connect() -- cgit v1.2.3