Skip to content

Commit 7476c27

Browse files
committed
Documentation updates
1 parent 58500cb commit 7476c27

File tree

5 files changed

+38
-24
lines changed

5 files changed

+38
-24
lines changed

CHANGELOG.md

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## 0.9.26 (TBD, 2020)
1+
## 1.0.0-rc1 (TBD, 2020)
22
* Enhancements
33
* Changed the default help text to make `help -v` more discoverable
44
* Added `add_settable()` and `remove_settable()` convenience methods to update `self.settable` dictionary
@@ -10,9 +10,11 @@
1010
* `prompt`
1111
* `self.settable` changed to `self.settables`
1212
* It is now a Dict[str, Settable] instead of Dict[str, str]
13+
* setting onchange callbacks have a new method signature and must be added to the
14+
Settable instance in order to be called
1315
* **set** command now supports tab-completion of values
1416
* Removed `cast()` utility function
15-
17+
1618
## 0.9.25 (January 26, 2020)
1719
* Enhancements
1820
* Reduced what gets put in package downloadable from PyPI (removed irrelevant CI config files and such)
@@ -74,7 +76,7 @@
7476
* Fix bug where cmd2 ran 'stty sane' command when stdin was not a terminal
7577
* Enhancements
7678
* Send all startup script paths to run_script. Previously we didn't do this if the file was empty, but that
77-
showed no record of the run_script command in history.
79+
showed no record of the run_script command in history.
7880
* Made it easier for developers to override `edit` command by having `do_history` no longer call `do_edit`. This
7981
also removes the need to exclude `edit` command from history list.
8082
* It is no longer necessary to set the `prog` attribute of an argparser with subcommands. cmd2 now automatically
@@ -143,7 +145,7 @@
143145
* Enhancements
144146
* Greatly simplified using argparse-based tab completion. The new interface is a complete overhaul that breaks
145147
the previous way of specifying completion and choices functions. See header of [argparse_custom.py](https://github.com/python-cmd2/cmd2/blob/master/cmd2/argparse_custom.py)
146-
for more information.
148+
for more information.
147149
* Enabled tab completion on multiline commands
148150
* **Renamed Commands Notice**
149151
* The following commands were renamed in the last release and have been removed in this release
@@ -153,7 +155,7 @@
153155
* We apologize for any inconvenience, but the new names are more self-descriptive
154156
* Lots of end users were confused particularly about what exactly `load` should be loading
155157
* Breaking Changes
156-
* Restored `cmd2.Cmd.statement_parser` to be a public attribute (no underscore)
158+
* Restored `cmd2.Cmd.statement_parser` to be a public attribute (no underscore)
157159
* Since it can be useful for creating [post-parsing hooks](https://cmd2.readthedocs.io/en/latest/features/hooks.html#postparsing-hooks)
158160
* Completely overhauled the interface for adding tab completion to argparse arguments. See enhancements for more details.
159161
* `ACArgumentParser` is now called `Cmd2ArgumentParser`
@@ -193,7 +195,7 @@
193195
* `perror` - print a message to sys.stderr
194196
* `pexcept` - print Exception message to sys.stderr. If debug is true, print exception traceback if one exists
195197
* Signature of `poutput` and `perror` significantly changed
196-
* Removed color parameters `color`, `err_color`, and `war_color` from `poutput` and `perror`
198+
* Removed color parameters `color`, `err_color`, and `war_color` from `poutput` and `perror`
197199
* See the docstrings of these methods or the [cmd2 docs](https://cmd2.readthedocs.io/en/latest/features/generating_output.html) for more info on applying styles to output messages
198200
* `end` argument is now keyword-only and cannot be specified positionally
199201
* `traceback_war` no longer exists as an argument since it isn't needed now that `perror` and `pexcept` exist
@@ -203,7 +205,7 @@
203205
* `COLORS_NEVER` --> `ANSI_NEVER`
204206
* `COLORS_TERMINAL` --> `ANSI_TERMINAL`
205207
* **Renamed Commands Notice**
206-
* The following commands have been renamed. The old names will be supported until the next release.
208+
* The following commands have been renamed. The old names will be supported until the next release.
207209
* `load` --> `run_script`
208210
* `_relative_load` --> `_relative_run_script`
209211
* `pyscript` --> `run_pyscript`
@@ -222,7 +224,7 @@
222224
* Fixed issue where `_cmdloop()` suppressed exceptions by returning from within its `finally` code
223225
* Fixed UnsupportedOperation on fileno error when a shell command was one of the commands run while generating
224226
a transcript
225-
* Fixed bug where history was displaying expanded multiline commands when -x was not specified
227+
* Fixed bug where history was displaying expanded multiline commands when -x was not specified
226228
* Enhancements
227229
* **Added capability to chain pipe commands and redirect their output (e.g. !ls -l | grep user | wc -l > out.txt)**
228230
* `pyscript` limits a command's stdout capture to the same period that redirection does.
@@ -243,7 +245,7 @@
243245
* Text scripts now run immediately instead of adding their commands to `cmdqueue`. This allows easy capture of
244246
the entire script's output.
245247
* Added member to `CommandResult` called `stop` which is the return value of `onecmd_plus_hooks` after it runs
246-
the given command line.
248+
the given command line.
247249
* Breaking changes
248250
* Replaced `unquote_redirection_tokens()` with `unquote_specific_tokens()`. This was to support the fix
249251
that allows terminators in alias and macro values.

docs/api/utility_classes.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
Utility Classes
22
===============
33

4+
.. autoclass:: cmd2.utils.Settable
5+
6+
.. automethod:: __init__
7+
48
.. autoclass:: cmd2.utils.StdSim
59

610
.. autoclass:: cmd2.utils.ByteBuf

docs/conf.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,6 @@
2525
# Import for custom theme from Read the Docs
2626
import sphinx_rtd_theme
2727

28-
sys.path.insert(0, os.path.abspath('..'))
29-
30-
3128
# -- General configuration -----------------------------------------------------
3229

3330
# If your documentation needs a minimal Sphinx version, state it here.

docs/features/settings.rst

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ Settings
33

44
Settings provide a mechanism for a user to control the behavior of a ``cmd2``
55
based application. A setting is stored in an instance attribute on your
6-
subclass of :class:`cmd2.cmd2.Cmd` and must also appear in the
7-
:attr:`cmd2.cmd2.Cmd.settable` dictionary. Developers may set default values
6+
subclass of :class:`.cmd2.Cmd` and must also appear in the
7+
:attr:`~.cmd2.Cmd.settable` dictionary. Developers may set default values
88
for these settings and users can modify them at runtime using the
99
:ref:`features/builtin_commands:set` command. Developers can
1010
:ref:`features/settings:Create New Settings` and can also
@@ -116,15 +116,21 @@ Create New Settings
116116
-------------------
117117

118118
Your application can define user-settable parameters which your code can
119-
reference. First create a class attribute with the default value. Then update
120-
the ``settable`` dictionary with your setting name and a short description
121-
before you initialize the superclass. Here's an example, from
119+
reference. In your initialization code:
120+
121+
1. Create an instance attribute with a default value.
122+
2. Create a :class:`.Settable` object which describes your setting.
123+
3. Pass the :class:`.Settable` object to
124+
:meth:`cmd2.cmd2.Cmd.add_settable`.
125+
126+
Here's an example, from
122127
``examples/environment.py``:
123128

124129
.. literalinclude:: ../../examples/environment.py
125130

126-
If you want to be notified when a setting changes (as we do above), then define
127-
a method ``_onchange_{setting}()``. This method will be called after the user
131+
If you want to be notified when a setting changes (as we do above), then be
132+
sure to supply a method to the ``onchange_cb`` parameter of the
133+
`.cmd2.utils.Settable`. This method will be called after the user
128134
changes a setting, and will receive both the old value and the new value.
129135

130136
.. code-block:: text
@@ -153,13 +159,14 @@ Hide Builtin Settings
153159
---------------------
154160

155161
You may want to prevent a user from modifying a builtin setting. A setting
156-
must appear in the :attr:`cmd2.cmd2.Cmd.settable` dictionary in order for it
162+
must appear in the :attr:`~.cmd2.Cmd.settable` dictionary in order for it
157163
to be available to the :ref:`features/builtin_commands:set` command.
158164

159165
Let's say that you never want end users of your program to be able to enable
160166
full debug tracebacks to print out if an error occurs. You might want to hide
161167
the :ref:`features/settings:debug` setting. To do so, remove it from the
162-
:attr:`cmd2.cmd2.Cmd.settable` dictionary after you initialize your object::
168+
:attr:`~.cmd2.Cmd.settable` dictionary after you initialize your object.
169+
The :meth:`~.cmd2.Cmd.remove_settable` convenience method makes this easy::
163170

164171
class MyApp(cmd2.Cmd):
165172

examples/environment.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,16 @@
88

99
class EnvironmentApp(cmd2.Cmd):
1010
""" Example cmd2 application. """
11-
degrees_c = 22
12-
sunny = False
1311

1412
def __init__(self):
1513
super().__init__()
16-
self.add_settable(cmd2.Settable('degrees_c', int, 'Temperature in Celsius'))
14+
self.degrees_c = 22
15+
self.sunny = False
16+
self.add_settable(cmd2.Settable('degrees_c',
17+
int,
18+
'Temperature in Celsius',
19+
onchange_cb=self._onchange_degrees_c
20+
))
1721
self.add_settable(cmd2.Settable('sunny', bool, 'Is it sunny outside?'))
1822

1923
def do_sunbathe(self, arg):

0 commit comments

Comments
 (0)