summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cmd2/cmd2.py8
-rwxr-xr-xexamples/help_categories.py5
2 files changed, 12 insertions, 1 deletions
diff --git a/cmd2/cmd2.py b/cmd2/cmd2.py
index 6b92a551..6b085a98 100644
--- a/cmd2/cmd2.py
+++ b/cmd2/cmd2.py
@@ -3665,6 +3665,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
@@ -3695,6 +3699,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()
diff --git a/examples/help_categories.py b/examples/help_categories.py
index e58bac02..62351e81 100755
--- a/examples/help_categories.py
+++ b/examples/help_categories.py
@@ -7,6 +7,7 @@ A sample application for tagging categories on commands.
import argparse
import cmd2
+from cmd2.cmd2 import COMMAND_NAME
class HelpCategories(cmd2.Cmd):
@@ -143,7 +144,9 @@ class HelpCategories(cmd2.Cmd):
@cmd2.with_category("Command Management")
def do_disable_commands(self, _):
"""Disable the Application Management commands"""
- self.disable_category(self.CMD_CAT_APP_MGMT, "Application Management is currently disabled")
+ message_to_print = "{} is not available while {} commands are disabled".format(COMMAND_NAME,
+ self.CMD_CAT_APP_MGMT)
+ self.disable_category(self.CMD_CAT_APP_MGMT, message_to_print)
self.poutput("The Application Management commands have been disabled")
@cmd2.with_category("Command Management")