summaryrefslogtreecommitdiff
path: root/cmd2/utils.py
diff options
context:
space:
mode:
authorTodd Leonhardt <todd.leonhardt@gmail.com>2020-02-20 15:12:24 -0500
committerGitHub <noreply@github.com>2020-02-20 15:12:24 -0500
commita2061ba7ce9e8482111d670e78fe890cf485b7c5 (patch)
treeb15906e7b7c3a4cac0013599431652cb9a654911 /cmd2/utils.py
parent660d41b404c00db5b757fd6888c50cb4903ad8ac (diff)
parenta62622a886713c845ba561d98778993c6362f65a (diff)
downloadcmd2-git-a2061ba7ce9e8482111d670e78fe890cf485b7c5.tar.gz
Merge pull request #895 from python-cmd2/relocate_functions
Moved categorize() to utils.py and made set_parser_prog() non-public
Diffstat (limited to 'cmd2/utils.py')
-rw-r--r--cmd2/utils.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/cmd2/utils.py b/cmd2/utils.py
index 6a67c43f..971a22ce 100644
--- a/cmd2/utils.py
+++ b/cmd2/utils.py
@@ -964,3 +964,18 @@ def get_styles_in_text(text: str) -> Dict[int, str]:
start += len(match.group())
return styles
+
+
+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)