summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkotfu <kotfu@kotfu.net>2020-02-20 20:51:00 -0700
committerkotfu <kotfu@kotfu.net>2020-02-20 20:51:00 -0700
commit387d13e75ae7b336b254481012b62361f72824f0 (patch)
treea10e1fa6f12e1a3e4b169fd1b9e3a2aaea514ab9
parent6b119fedafbbf655d244f8fcdc4563ec011c3ecf (diff)
downloadcmd2-git-387d13e75ae7b336b254481012b62361f72824f0.tar.gz
Embedded examples and cross-links for categorize() and with_category()
-rw-r--r--cmd2/decorators.py3
-rw-r--r--cmd2/utils.py14
2 files changed, 16 insertions, 1 deletions
diff --git a/cmd2/decorators.py b/cmd2/decorators.py
index a8babcac..e9aff0eb 100644
--- a/cmd2/decorators.py
+++ b/cmd2/decorators.py
@@ -19,6 +19,9 @@ def with_category(category: str) -> Callable:
>>> @cmd2.with_category('Text Functions')
>>> def do_echo(self, args)
>>> self.poutput(args)
+
+ For an alternative approach to categorizing commands using a function, see
+ :func:`~cmd2.utils.categorize`
"""
def cat_decorator(func):
from .utils import categorize
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: