cliutil: Add docstrings throughout.

This commit is contained in:
Brett Smith 2021-04-29 11:49:46 -04:00
parent 323521344a
commit af0fb50014

View file

@ -1,4 +1,13 @@
"""cliutil - Utilities for CLI tools""" """cliutil - Utilities for CLI tools
This module provides common functionality for
* command line argument parsing
* exception handling
* exit status reporting
* file opening that deals with the ``-`` convention
* logging
"""
PKGNAME = 'conservancy_beancount' PKGNAME = 'conservancy_beancount'
LICENSE = """ LICENSE = """
Copyright © 2020, 2021 Brett Smith and other contributors Copyright © 2020, 2021 Brett Smith and other contributors
@ -127,6 +136,13 @@ class EnumArgument(Generic[ET]):
class ExceptHook: class ExceptHook:
"""Common ExceptHook
Interactive tools can install an instance of this class as
``sys.excepthook``. It knows how to generate more user-friendly error
messages and exit codes for common exception types, and reports those to
the given logger (or the root logger if none was given).
"""
def __init__(self, logger: Optional[logging.Logger]=None) -> None: def __init__(self, logger: Optional[logging.Logger]=None) -> None:
if logger is None: if logger is None:
logger = logging.getLogger() logger = logging.getLogger()
@ -233,6 +249,13 @@ class ExtendAction(argparse.Action):
class InfoAction(argparse.Action): class InfoAction(argparse.Action):
"""argparse action to print information and exit
Use this for options like ``--version`` and ``--license``.
The argument ``const`` can either be a 2-tuple (str, int) with the
message to print and exit code to use; or just a string message, and it
will default to using the OK exit code 0.
"""
def __call__(self, def __call__(self,
parser: argparse.ArgumentParser, parser: argparse.ArgumentParser,
namespace: argparse.Namespace, namespace: argparse.Namespace,