summaryrefslogtreecommitdiff
path: root/docs/features
diff options
context:
space:
mode:
authorkotfu <kotfu@kotfu.net>2020-02-05 20:56:29 -0700
committerkotfu <kotfu@kotfu.net>2020-02-05 20:56:29 -0700
commit7476c27e95b6a9c1ee1c93893d678012c019cf7c (patch)
tree469fb2f21d78de458f80f276bda0d6f8a73fe554 /docs/features
parent58500cb0b86e8046b49aac5d554a6fa9630c0cd3 (diff)
downloadcmd2-git-7476c27e95b6a9c1ee1c93893d678012c019cf7c.tar.gz
Documentation updates
Diffstat (limited to 'docs/features')
-rw-r--r--docs/features/settings.rst25
1 files changed, 16 insertions, 9 deletions
diff --git a/docs/features/settings.rst b/docs/features/settings.rst
index 23c7686d..40b9bc35 100644
--- a/docs/features/settings.rst
+++ b/docs/features/settings.rst
@@ -3,8 +3,8 @@ Settings
Settings provide a mechanism for a user to control the behavior of a ``cmd2``
based application. A setting is stored in an instance attribute on your
-subclass of :class:`cmd2.cmd2.Cmd` and must also appear in the
-:attr:`cmd2.cmd2.Cmd.settable` dictionary. Developers may set default values
+subclass of :class:`.cmd2.Cmd` and must also appear in the
+:attr:`~.cmd2.Cmd.settable` dictionary. Developers may set default values
for these settings and users can modify them at runtime using the
:ref:`features/builtin_commands:set` command. Developers can
:ref:`features/settings:Create New Settings` and can also
@@ -116,15 +116,21 @@ Create New Settings
-------------------
Your application can define user-settable parameters which your code can
-reference. First create a class attribute with the default value. Then update
-the ``settable`` dictionary with your setting name and a short description
-before you initialize the superclass. Here's an example, from
+reference. In your initialization code:
+
+1. Create an instance attribute with a default value.
+2. Create a :class:`.Settable` object which describes your setting.
+3. Pass the :class:`.Settable` object to
+ :meth:`cmd2.cmd2.Cmd.add_settable`.
+
+Here's an example, from
``examples/environment.py``:
.. literalinclude:: ../../examples/environment.py
-If you want to be notified when a setting changes (as we do above), then define
-a method ``_onchange_{setting}()``. This method will be called after the user
+If you want to be notified when a setting changes (as we do above), then be
+sure to supply a method to the ``onchange_cb`` parameter of the
+`.cmd2.utils.Settable`. This method will be called after the user
changes a setting, and will receive both the old value and the new value.
.. code-block:: text
@@ -153,13 +159,14 @@ Hide Builtin Settings
---------------------
You may want to prevent a user from modifying a builtin setting. A setting
-must appear in the :attr:`cmd2.cmd2.Cmd.settable` dictionary in order for it
+must appear in the :attr:`~.cmd2.Cmd.settable` dictionary in order for it
to be available to the :ref:`features/builtin_commands:set` command.
Let's say that you never want end users of your program to be able to enable
full debug tracebacks to print out if an error occurs. You might want to hide
the :ref:`features/settings:debug` setting. To do so, remove it from the
-:attr:`cmd2.cmd2.Cmd.settable` dictionary after you initialize your object::
+:attr:`~.cmd2.Cmd.settable` dictionary after you initialize your object.
+The :meth:`~.cmd2.Cmd.remove_settable` convenience method makes this easy::
class MyApp(cmd2.Cmd):