diff options
author | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2020-02-18 12:59:46 -0500 |
---|---|---|
committer | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2020-02-18 12:59:46 -0500 |
commit | d3deca3c99c299149a30aa3ec760dc17f8abc456 (patch) | |
tree | 58ac6df4330780cec94e854782a7bfae23c16589 /cmd2/utils.py | |
parent | 065536a484bb705e1e6b7971fc4c8efdb637185e (diff) | |
download | cmd2-git-d3deca3c99c299149a30aa3ec760dc17f8abc456.tar.gz |
Added apply_style to CompletionError
Simplified error class structure in argparse_completer.py
Diffstat (limited to 'cmd2/utils.py')
-rw-r--r-- | cmd2/utils.py | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/cmd2/utils.py b/cmd2/utils.py index b6b45891..6a67c43f 100644 --- a/cmd2/utils.py +++ b/cmd2/utils.py @@ -75,12 +75,26 @@ def str_to_bool(val: str) -> bool: class CompletionError(Exception): """ Raised during tab completion operations to report any sort of error you want printed by the ArgparseCompleter + This can also be used just to display a message, even if it's not an error. ArgparseCompleter raises + CompletionErrors to display tab completion hints and sets apply_style to False so hints aren't colored + like error text. Example use cases - Reading a database to retrieve a tab completion data set failed - A previous command line argument that determines the data set being completed is invalid + - Tab completion hints """ - pass + def __init__(self, *args, apply_style: bool = True, **kwargs): + """ + Initializer for CompletionError + :param apply_style: If True, then ansi.style_error will be applied to the message text when printed. + Set to False in cases where the message text already has the desired style. + Defaults to True. + """ + self.apply_style = apply_style + + # noinspection PyArgumentList + super().__init__(*args, **kwargs) class Settable: |