diff options
author | Todd Leonhardt <todd.leonhardt@gmail.com> | 2020-02-06 18:29:21 -0500 |
---|---|---|
committer | Todd Leonhardt <todd.leonhardt@gmail.com> | 2020-02-06 18:29:21 -0500 |
commit | 0d74ed61ef5a9ec7fbaca371b9af2195a867d223 (patch) | |
tree | 7758962c2e8e066098765a31e0ff1f6e97fafcfb /docs/features | |
parent | bf3dc169c047acda1c1cf505e8cd0e9e46d4b4cf (diff) | |
parent | c7ac2e965d025806ce5baddfc718814e3e58d639 (diff) | |
download | cmd2-git-0d74ed61ef5a9ec7fbaca371b9af2195a867d223.tar.gz |
Merge branch 'master' into doc_streamline
# Conflicts:
# docs/features/settings.rst
Diffstat (limited to 'docs/features')
-rw-r--r-- | docs/features/builtin_commands.rst | 6 | ||||
-rw-r--r-- | docs/features/initialization.rst | 7 | ||||
-rw-r--r-- | docs/features/plugins.rst | 4 | ||||
-rw-r--r-- | docs/features/settings.rst | 22 |
4 files changed, 24 insertions, 15 deletions
diff --git a/docs/features/builtin_commands.rst b/docs/features/builtin_commands.rst index d2cefa71..0db05c96 100644 --- a/docs/features/builtin_commands.rst +++ b/docs/features/builtin_commands.rst @@ -93,10 +93,10 @@ within a running application: (Cmd) set --long allow_style: Terminal # Allow ANSI text style sequences in output (valid values: Terminal, Always, Never) - debug: False # Show full error stack on error + debug: False # Show full traceback on exception echo: False # Echo command issued into output - editor: vim # Program used by ``edit`` - feedback_to_output: False # include nonessentials in `|`, `>` results + editor: vim # Program used by 'edit' + feedback_to_output: False # include nonessentials in '|', '>' results max_completion_items: 50 # Maximum number of CompletionItems to display during tab completion quiet: False # Don't print nonessential feedback timing: False # Report execution times diff --git a/docs/features/initialization.rst b/docs/features/initialization.rst index 9924caa2..5721caa3 100644 --- a/docs/features/initialization.rst +++ b/docs/features/initialization.rst @@ -20,7 +20,7 @@ capabilities which you may wish to utilize while initializing the app:: """ import cmd2 from cmd2 import style - + from cmd2.ansi import FG_COLORS class BasicApp(cmd2.Cmd): CUSTOM_CATEGORY = 'My Custom Commands' @@ -48,7 +48,10 @@ capabilities which you may wish to utilize while initializing the app:: self.foreground_color = 'cyan' # Make echo_fg settable at runtime - self.settable['foreground_color'] = 'Foreground color to use with echo command' + self.add_settable(cmd2.Settable('foreground_color', + str, + 'Foreground color to use with echo command', + choices=FG_COLORS)) @cmd2.with_category(CUSTOM_CATEGORY) def do_intro(self, _): diff --git a/docs/features/plugins.rst b/docs/features/plugins.rst index caa46b8c..00c0a9f0 100644 --- a/docs/features/plugins.rst +++ b/docs/features/plugins.rst @@ -82,10 +82,10 @@ example:: super().__init__(*args, **kwargs) # code placed here runs after cmd2.Cmd initializes self.mysetting = 'somevalue' - self.settable.update({'mysetting': 'short help message for mysetting'}) + self.add_settable(cmd2.Settable('mysetting', str, 'short help message for mysetting')) You can also hide settings from the user by removing them from -``self.settable``. +``self.settables``. Decorators ~~~~~~~~~~ diff --git a/docs/features/settings.rst b/docs/features/settings.rst index cece62b7..5a4a9c0f 100644 --- a/docs/features/settings.rst +++ b/docs/features/settings.rst @@ -116,15 +116,20 @@ 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.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 @@ -150,7 +155,7 @@ changes a setting, and will receive both the old value and the new value. Hide Builtin Settings ----------------------- +--------------------- You may want to prevent a user from modifying a builtin setting. A setting must appear in the :attr:`cmd2.Cmd.settable` dictionary in order for it @@ -159,10 +164,11 @@ 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.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): def __init__(self): super().__init__() - self.settable.pop('debug') + self.remove_settable('debug') |