summaryrefslogtreecommitdiff
path: root/docs/features/misc.rst
diff options
context:
space:
mode:
Diffstat (limited to 'docs/features/misc.rst')
-rw-r--r--docs/features/misc.rst70
1 files changed, 70 insertions, 0 deletions
diff --git a/docs/features/misc.rst b/docs/features/misc.rst
index b556d44e..0ddc03e1 100644
--- a/docs/features/misc.rst
+++ b/docs/features/misc.rst
@@ -77,3 +77,73 @@ like so::
This text file should contain a :ref:`Command Script
<features/scripting:Command Scripts>`. See the AliasStartup_ example for a
demonstration.
+
+
+select
+------
+
+Presents numbered options to user, as bash ``select``.
+
+``app.select`` is called from within a method (not by the user directly; it is
+``app.select``, not ``app.do_select``).
+
+.. automethod:: cmd2.cmd2.Cmd.select
+ :noindex:
+
+::
+
+ def do_eat(self, arg):
+ sauce = self.select('sweet salty', 'Sauce? ')
+ result = '{food} with {sauce} sauce, yum!'
+ result = result.format(food=arg, sauce=sauce)
+ self.stdout.write(result + '\n')
+
+::
+
+ (Cmd) eat wheaties
+ 1. sweet
+ 2. salty
+ Sauce? 2
+ wheaties with salty sauce, yum!
+
+
+Disabling Commands
+------------------
+
+``cmd2`` supports disabling commands during runtime. This is useful if certain
+commands should only be available when the application is in a specific state.
+When a command is disabled, it will not show up in the help menu or tab
+complete. If a user tries to run the command, a command-specific message
+supplied by the developer will be printed. The following functions support this
+feature.
+
+enable_command()
+ Enable an individual command
+
+enable_category()
+ Enable an entire category of commands
+
+disable_command()
+ Disable an individual command and set the message that will print when this
+ command is run or help is called on it while disabled
+
+disable_category()
+ Disable an entire category of commands and set the message that will print
+ when anything in this category is run or help is called on it while
+ disabled
+
+See the definitions of these functions for descriptions of their arguments.
+
+See the ``do_enable_commands()`` and ``do_disable_commands()`` functions in the
+HelpCategories_ example for a demonstration.
+
+.. _HelpCategories: https://github.com/python-cmd2/cmd2/blob/master/examples/help_categories.py
+
+
+Exit code
+---------
+
+The ``self.exit_code`` attribute of your ``cmd2`` application controls what
+exit code is returned from ``cmdloop()`` when it completes. It is your job to
+make sure that this exit code gets sent to the shell when your application
+exits by calling ``sys.exit(app.cmdloop())``.