summaryrefslogtreecommitdiff
path: root/cmd2/cmd2.py
diff options
context:
space:
mode:
authorTodd Leonhardt <todd.leonhardt@gmail.com>2019-03-14 19:29:44 -0400
committerTodd Leonhardt <todd.leonhardt@gmail.com>2019-03-14 19:29:44 -0400
commiteb050d7ad09a4c17f4f2ef3d59735cf87272aded (patch)
tree072443e9c49720cd343ebde68f4cdf762c3d964f /cmd2/cmd2.py
parentd2ebee4a6e55798f9d5fa41f8e2a200005b87cde (diff)
parent177297ae557383215f3dae698ff43e1cf9daecca (diff)
downloadcmd2-git-eb050d7ad09a4c17f4f2ef3d59735cf87272aded.tar.gz
Merge branch 'master' into attributes
Diffstat (limited to 'cmd2/cmd2.py')
-rw-r--r--cmd2/cmd2.py19
1 files changed, 16 insertions, 3 deletions
diff --git a/cmd2/cmd2.py b/cmd2/cmd2.py
index 2da8f561..d13f6335 100644
--- a/cmd2/cmd2.py
+++ b/cmd2/cmd2.py
@@ -135,6 +135,9 @@ HELP_FUNC_PREFIX = 'help_'
ALPHABETICAL_SORT_KEY = utils.norm_fold
NATURAL_SORT_KEY = utils.natural_keys
+# Used as the command name placeholder in disabled command messages.
+COMMAND_NAME = "<COMMAND_NAME>"
+
def categorize(func: Union[Callable, Iterable], category: str) -> None:
"""Categorize a function.
@@ -2063,7 +2066,8 @@ class Cmd(cmd.Cmd):
return self.do_shell(statement.command_and_args)
else:
- self.poutput('*** {} is not a recognized command, alias, or macro\n'.format(statement.command))
+ self.perror('*** {} is not a recognized command, alias, or macro'.format(statement.command),
+ err_color=Fore.RESET, traceback_war=False)
def pseudo_raw_input(self, prompt: str) -> str:
"""Began life as a copy of cmd's cmdloop; like raw_input but
@@ -3678,6 +3682,10 @@ class Cmd(cmd.Cmd):
Disable a command and overwrite its functions
:param command: the command being disabled
:param message_to_print: what to print when this command is run or help is called on it while disabled
+
+ The variable COMMAND_NAME can be used as a placeholder for the name of the
+ command being disabled.
+ ex: message_to_print = "{} is currently disabled".format(COMMAND_NAME)
"""
import functools
@@ -3697,7 +3705,8 @@ class Cmd(cmd.Cmd):
help_function=getattr(self, help_func_name, None))
# Overwrite the command and help functions to print the message
- new_func = functools.partial(self._report_disabled_command_usage, message_to_print=message_to_print)
+ new_func = functools.partial(self._report_disabled_command_usage,
+ message_to_print=message_to_print.replace(COMMAND_NAME, command))
setattr(self, self.cmd_func_name(command), new_func)
setattr(self, help_func_name, new_func)
@@ -3707,6 +3716,10 @@ class Cmd(cmd.Cmd):
:param category: the category to disable
:param message_to_print: what to print when anything in this category is run or help is called on it
while disabled
+
+ The variable COMMAND_NAME can be used as a placeholder for the name of the
+ command being disabled.
+ ex: message_to_print = "{} is currently disabled".format(COMMAND_NAME)
"""
all_commands = self.get_all_commands()
@@ -3723,7 +3736,7 @@ class Cmd(cmd.Cmd):
:param message_to_print: the message reporting that the command is disabled
:param kwargs: not used
"""
- self.poutput(message_to_print)
+ self.perror(message_to_print, err_color=Fore.RESET, traceback_war=False)
def cmdloop(self, intro: Optional[str] = None) -> None:
"""This is an outer wrapper around _cmdloop() which deals with extra features provided by cmd2.