summaryrefslogtreecommitdiff
path: root/cmd2.py
diff options
context:
space:
mode:
authorEric Lin <anselor@gmail.com>2018-04-09 18:14:31 -0400
committerEric Lin <anselor@gmail.com>2018-04-09 18:14:31 -0400
commitef23633daba9538360af61d7547e8d0d0f6c1139 (patch)
tree834317ca11c5619348af6344688f075e5f7d174e /cmd2.py
parent5d1e981ee18136d41574c20e10a77f1b0e8b30a1 (diff)
downloadcmd2-git-ef23633daba9538360af61d7547e8d0d0f6c1139.tar.gz
Added a convenience function for tagging command categories.
Diffstat (limited to 'cmd2.py')
-rwxr-xr-xcmd2.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/cmd2.py b/cmd2.py
index c2cea659..1d2751c4 100755
--- a/cmd2.py
+++ b/cmd2.py
@@ -42,6 +42,7 @@ import six
import sys
import tempfile
import traceback
+from typing import Union, Callable
import unittest
from code import InteractiveConsole
@@ -212,6 +213,18 @@ REDIRECTION_CHARS = ['|', '<', '>']
HELP_CATEGORY = 'help_category'
+def categorize(func: Union[Callable, Iterable], category: str):
+ """
+ Categorize a function
+ The help command output will group this function under the specified category heading
+ """
+ if isinstance(func, Iterable):
+ for item in func:
+ setattr(item, HELP_CATEGORY, category)
+ else:
+ setattr(func, HELP_CATEGORY, category)
+
+
def set_posix_shlex(val):
""" Allows user of cmd2 to choose between POSIX and non-POSIX splitting of args for decorated commands.