diff options
author | Todd Leonhardt <todd.leonhardt@gmail.com> | 2020-02-04 23:01:30 -0500 |
---|---|---|
committer | Todd Leonhardt <todd.leonhardt@gmail.com> | 2020-02-04 23:01:30 -0500 |
commit | 40722f10ace3107dcb4709008239ac8233ada30f (patch) | |
tree | 676edd56ec5ba1287cd4f38b66f2733eea597ee9 /docs | |
parent | 61dfcf613966355d68c01f2aa06f0158b54c1f20 (diff) | |
download | cmd2-git-40722f10ace3107dcb4709008239ac8233ada30f.tar.gz |
Added cmd2.utils.Settable to the cmd2 namespace and updated examples and docs
Diffstat (limited to 'docs')
-rw-r--r-- | docs/examples/first_app.rst | 4 | ||||
-rw-r--r-- | docs/features/initialization.rst | 7 | ||||
-rw-r--r-- | docs/features/plugins.rst | 4 | ||||
-rw-r--r-- | docs/features/settings.rst | 4 |
4 files changed, 11 insertions, 8 deletions
diff --git a/docs/examples/first_app.rst b/docs/examples/first_app.rst index 19d573b4..310c8d0c 100644 --- a/docs/examples/first_app.rst +++ b/docs/examples/first_app.rst @@ -67,7 +67,7 @@ initializer to our class:: # Make maxrepeats settable at runtime self.maxrepeats = 3 - self.settable['maxrepeats'] = 'max repetitions for speak command' + self.add_settable(cmd2.Settable('maxrepeats', int, 'max repetitions for speak command')) In that initializer, the first thing to do is to make sure we initialize ``cmd2``. That's what the ``super().__init__()`` line does. Then we create an @@ -203,7 +203,7 @@ method so it looks like this:: # Make maxrepeats settable at runtime self.maxrepeats = 3 - self.settable['maxrepeats'] = 'max repetitions for speak command' + self.add_settable(cmd2.Settable('maxrepeats', int, 'max repetitions for speak command')) Shortcuts are passed to the ``cmd2`` initializer, and if you want the built-in shortcuts of ``cmd2`` you have to pass them. These shortcuts are defined as a diff --git a/docs/features/initialization.rst b/docs/features/initialization.rst index 46b4ecd2..d48290fa 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 55b6a10d..6a8996e1 100644 --- a/docs/features/settings.rst +++ b/docs/features/settings.rst @@ -150,7 +150,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.cmd2.Cmd.settable` dictionary in order for it @@ -165,4 +165,4 @@ the :ref:`features/settings:debug` setting. To do so, remove it from the def __init__(self): super().__init__() - self.settable.pop('debug') + self.settables.pop('debug') |