From 721ed499bbe028c8984925fb075845feef445447 Mon Sep 17 00:00:00 2001 From: Romain Dorgueil Date: Thu, 12 Oct 2017 19:02:11 +0200 Subject: [PATCH] [config] adds a __doc__ constructor kwarg to set option documentation inline. --- bonobo/config/options.py | 4 +++- bonobo/nodes/basics.py | 8 ++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/bonobo/config/options.py b/bonobo/config/options.py index 065cc9d..cad4ca8 100644 --- a/bonobo/config/options.py +++ b/bonobo/config/options.py @@ -53,13 +53,15 @@ class Option: _creation_counter = 0 - def __init__(self, type=None, *, required=True, positional=False, default=None): + def __init__(self, type=None, *, required=True, positional=False, default=None, __doc__=None): self.name = None self.type = type self.required = required if default is None else False self.positional = positional self.default = default + self.__doc__ = __doc__ or self.__doc__ + # This hack is necessary for python3.5 self._creation_counter = Option._creation_counter Option._creation_counter += 1 diff --git a/bonobo/nodes/basics.py b/bonobo/nodes/basics.py index b346404..fa74e40 100644 --- a/bonobo/nodes/basics.py +++ b/bonobo/nodes/basics.py @@ -77,9 +77,13 @@ def _shorten(s, w): class PrettyPrinter(Configurable): - max_width = Option(int, required=False, __doc__=''' + max_width = Option( + int, + required=False, + __doc__=''' If set, truncates the output values longer than this to this width. - ''') + ''' + ) def call(self, *args, **kwargs): formater = self._format_quiet if settings.QUIET.get() else self._format_console