From 51c831d2f28609c736a0d649b04e7d2e3b3d742a Mon Sep 17 00:00:00 2001 From: kotfu Date: Fri, 14 Feb 2020 21:02:02 -0700 Subject: move `categorize()` to `utils.py` and make `set_parser_prog` a private method --- cmd2/utils.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'cmd2/utils.py') diff --git a/cmd2/utils.py b/cmd2/utils.py index e324c2f1..74df7444 100644 --- a/cmd2/utils.py +++ b/cmd2/utils.py @@ -404,6 +404,21 @@ def get_exes_in_path(starts_with: str) -> List[str]: return list(exes_set) +def categorize(func: Union[Callable, Iterable[Callable]], category: str) -> None: + """Categorize a function. + + The help command output will group this function under the specified category heading + + :param func: function or list of functions to categorize + :param category: category to put it in + """ + if isinstance(func, Iterable): + for item in func: + setattr(item, constants.CMD_ATTR_HELP_CATEGORY, category) + else: + setattr(func, constants.CMD_ATTR_HELP_CATEGORY, category) + + class StdSim: """ Class to simulate behavior of sys.stdout or sys.stderr. -- cgit v1.2.1 From 6b119fedafbbf655d244f8fcdc4563ec011c3ecf Mon Sep 17 00:00:00 2001 From: kotfu Date: Thu, 20 Feb 2020 20:38:09 -0700 Subject: Fix merge error --- cmd2/utils.py | 15 --------------- 1 file changed, 15 deletions(-) (limited to 'cmd2/utils.py') diff --git a/cmd2/utils.py b/cmd2/utils.py index d02d8157..971a22ce 100644 --- a/cmd2/utils.py +++ b/cmd2/utils.py @@ -429,21 +429,6 @@ def get_exes_in_path(starts_with: str) -> List[str]: return list(exes_set) -def categorize(func: Union[Callable, Iterable[Callable]], category: str) -> None: - """Categorize a function. - - The help command output will group this function under the specified category heading - - :param func: function or list of functions to categorize - :param category: category to put it in - """ - if isinstance(func, Iterable): - for item in func: - setattr(item, constants.CMD_ATTR_HELP_CATEGORY, category) - else: - setattr(func, constants.CMD_ATTR_HELP_CATEGORY, category) - - class StdSim: """ Class to simulate behavior of sys.stdout or sys.stderr. -- cgit v1.2.1 From 387d13e75ae7b336b254481012b62361f72824f0 Mon Sep 17 00:00:00 2001 From: kotfu Date: Thu, 20 Feb 2020 20:51:00 -0700 Subject: Embedded examples and cross-links for categorize() and with_category() --- cmd2/utils.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'cmd2/utils.py') diff --git a/cmd2/utils.py b/cmd2/utils.py index 971a22ce..2f0e8bcf 100644 --- a/cmd2/utils.py +++ b/cmd2/utils.py @@ -969,10 +969,22 @@ def get_styles_in_text(text: str) -> Dict[int, str]: def categorize(func: Union[Callable, Iterable[Callable]], category: str) -> None: """Categorize a function. - The help command output will group this function under the specified category heading + The help command output will group the passed function under the + specified category heading :param func: function or list of functions to categorize :param category: category to put it in + + :Example: + + >>> class MyApp(cmd2.Cmd): + >>> def do_echo(self, arglist): + >>> self.poutput(' '.join(arglist) + >>> + >>> utils.categorize(do_echo, "Text Processing") + + For an alternative approach to categorizing commands using a decorator, see + :func:`~cmd2.decorators.with_category` """ if isinstance(func, Iterable): for item in func: -- cgit v1.2.1