Skip to content

Commit 0f8f90c

Browse files
committed
Made three public attributes of cmd2.Cmd no longer settable at runtime by end users
The 3 attributes are: - continuation_prompt - locals_in_py - prompt
1 parent 95f8d88 commit 0f8f90c

File tree

16 files changed

+49
-72
lines changed

16 files changed

+49
-72
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
## 0.9.26 (January 26, 2020)
2+
* Breaking changes
3+
* The following public attributes of `cmd2.Cmd` are no longer settable at runtime by end users:
4+
* `continuation_prompt`
5+
* `locals_in_py`
6+
* `prompt`
7+
18
## 0.9.25 (January 26, 2020)
29
* Enhancements
310
* Reduced what gets put in package downloadable from PyPI (removed irrelevant CI config files and such)

cmd2/cmd2.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -188,21 +188,18 @@ def __init__(self, completekey: str = 'tab', stdin=None, stdout=None, *,
188188
self.allow_redirection = allow_redirection # Security setting to prevent redirection of stdout
189189

190190
# Attributes which ARE dynamically settable via the set command at runtime
191-
self.continuation_prompt = '> '
192191
self.debug = False
193192
self.echo = False
194193
self.editor = Cmd.DEFAULT_EDITOR
195194
self.feedback_to_output = False # Do not include nonessentials in >, | output by default (things like timing)
196-
self.locals_in_py = False
195+
self.quiet = False # Do not suppress nonessential output
196+
self.timing = False # Prints elapsed time for each command
197197

198198
# The maximum number of CompletionItems to display during tab completion. If the number of completion
199199
# suggestions exceeds this number, they will be displayed in the typical columnized format and will
200200
# not include the description value of the CompletionItems.
201201
self.max_completion_items = 50
202202

203-
self.quiet = False # Do not suppress nonessential output
204-
self.timing = False # Prints elapsed time for each command
205-
206203
# To make an attribute settable with the "do_set" command, add it to this ...
207204
self.settable = \
208205
{
@@ -211,18 +208,21 @@ def __init__(self, completekey: str = 'tab', stdin=None, stdout=None, *,
211208
'(valid values: {}, {}, {})'.format(ansi.STYLE_TERMINAL,
212209
ansi.STYLE_ALWAYS,
213210
ansi.STYLE_NEVER)),
214-
'continuation_prompt': 'On 2nd+ line of input',
215211
'debug': 'Show full error stack on error',
216212
'echo': 'Echo command issued into output',
217213
'editor': 'Program used by ``edit``',
218214
'feedback_to_output': 'Include nonessentials in `|`, `>` results',
219-
'locals_in_py': 'Allow access to your application in py via self',
220215
'max_completion_items': 'Maximum number of CompletionItems to display during tab completion',
221-
'prompt': 'The prompt issued to solicit input',
222216
'quiet': "Don't print nonessential feedback",
223217
'timing': 'Report execution times'
224218
}
225219

220+
# Use as prompt for multiline commands on the 2nd+ line of input
221+
self.continuation_prompt = '> '
222+
223+
# Allow access to your application in embedded Python shells and scripts py via self
224+
self.locals_in_py = False
225+
226226
# Commands to exclude from the help menu and tab completion
227227
self.hidden_commands = ['eof', '_relative_load', '_relative_run_script']
228228

docs/features/builtin_commands.rst

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,11 @@ within a running application:
9393
9494
(Cmd) set --long
9595
allow_style: Terminal # Allow ANSI text style sequences in output (valid values: Terminal, Always, Never)
96-
continuation_prompt: > # On 2nd+ line of input
9796
debug: False # Show full error stack on error
9897
echo: False # Echo command issued into output
9998
editor: vim # Program used by ``edit``
10099
feedback_to_output: False # include nonessentials in `|`, `>` results
101-
locals_in_py: False # Allow access to your application in py via self
102100
max_completion_items: 50 # Maximum number of CompletionItems to display during tab completion
103-
prompt: (Cmd) # The prompt issued to solicit input
104101
quiet: False # Don't print nonessential feedback
105102
timing: False # Report execution times
106103

docs/features/embedded_python_shells.rst

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ your cmd2 application while maintaining isolation.
1010
You may optionally enable full access to to your application by setting
1111
``locals_in_py`` to ``True``. Enabling this flag adds ``self`` to the python
1212
session, which is a reference to your Cmd2 application. This can be useful for
13-
debugging your application. To prevent users from enabling this ability
14-
manually you'll need to remove ``locals_in_py`` from the ``settable``
15-
dictionary.
13+
debugging your application.
1614

1715
The ``app`` object (or your custom name) provides access to application
1816
commands through raw commands. For example, any application command call be

docs/features/initialization.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ override:
110110
DisabledCommand objects.
111111
- **echo**: if ``True``, each command the user issues will be repeated to the
112112
screen before it is executed. This is particularly useful when running
113-
scripts. This behavior does not occur when a running command at the prompt.
113+
scripts. This behavior does not occur when running a command at the prompt.
114114
(Default: ``False``)
115115
- **editor**: text editor program to use with *edit* command (e.g. ``vim``)
116116
- **exclude_from_history**: commands to exclude from the *history* command

docs/features/multiline_commands.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,13 @@ blank line is *always* considered a command terminator (cannot be overridden).
1010

1111
In multiline commands, output redirection characters like ``>`` and ``|`` are
1212
part of the command arguments unless they appear after the terminator.
13+
14+
Continuation prompt
15+
-------------------
16+
17+
When a user types a :ref:`Multiline Command
18+
<features/multiline_commands:Multiline Commands>` it may span more than one
19+
line of input. The prompt for the first line of input is specified by the
20+
``cmd2.Cmd.prompt`` instance attribute - see
21+
:ref:`features/prompt:Customizing the Prompt`. The prompt for subsequent lines
22+
of input is defined by the ``cmd2.Cmd.continuation_prompt`` attribute.

docs/features/prompt.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@ Prompt
33

44
``cmd2`` can issue a prompt before soliciting user input.
55

6+
Customizing the Prompt
7+
----------------------
8+
9+
This prompt can be configured by setting the `cmd2.Cmd.prompt` instance
10+
attribute. This contains the string which should be printed as a prompt
11+
for user input.
12+
613
Asynchronous Feedback
714
---------------------
815

docs/features/settings.rst

Lines changed: 5 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,6 @@ This setting can be one of three values:
4747
- ``Always`` - ANSI escape sequences are always passed through to the output
4848

4949

50-
continuation_prompt
51-
~~~~~~~~~~~~~~~~~~~
52-
53-
When a user types a :ref:`Multiline Command
54-
<features/multiline_commands:Multiline Commands>` it may span more than one
55-
line of input. The prompt for the first line of input is specified by the
56-
:ref:`features/settings:prompt` setting. The prompt for subsequent lines of
57-
input is defined by this setting.
58-
59-
6050
debug
6151
~~~~~
6252

@@ -71,7 +61,7 @@ echo
7161

7262
If ``True``, each command the user issues will be repeated to the screen
7363
before it is executed. This is particularly useful when running scripts.
74-
This behavior does not occur when a running command at the prompt.
64+
This behavior does not occur when running a command at the prompt.
7565

7666

7767
editor
@@ -95,13 +85,6 @@ feedback output will be mixed in with and indistinguishable from output
9585
generated with :meth:`~cmd2.cmd2.Cmd.poutput`.
9686

9787

98-
locals_in_py
99-
~~~~~~~~~~~~
100-
101-
Allow access to your application in one of the
102-
:ref:`features/embedded_python_shells:Embedded Python Shells` via ``self``.
103-
104-
10588
max_completion_items
10689
~~~~~~~~~~~~~~~~~~~~
10790

@@ -115,13 +98,6 @@ they will be displayed in the typical columnized format and will not include
11598
the description text of the CompletionItem.
11699

117100

118-
prompt
119-
~~~~~~
120-
121-
This setting contains the string which should be printed as a prompt for user
122-
input.
123-
124-
125101
quiet
126102
~~~~~
127103

@@ -180,14 +156,13 @@ You may want to prevent a user from modifying a builtin setting. A setting
180156
must appear in the :attr:`cmd2.cmd2.Cmd.settable` dictionary in order for it
181157
to be available to the :ref:`features/builtin_commands:set` command.
182158

183-
Let's say your program does not have any
184-
:ref:`features/multiline_commands:Multiline Commands`. You might want to hide
185-
the :ref:`features/settings:continuation_prompt` setting from your users since
186-
it is only applicable to multiline commands. To do so, remove it from the
159+
Let's say that you never want end users of your program to be able to enable
160+
full debug tracebacks to print out if an error occurs. You might want to hide
161+
the :ref:`features/settings:debug` setting. To do so, remove it from the
187162
:attr:`cmd2.cmd2.Cmd.settable` dictionary after you initialize your object::
188163

189164
class MyApp(cmd2.Cmd):
190165

191166
def __init__(self):
192167
super().__init__()
193-
self.settable.pop('continuation_prompt')
168+
self.settable.pop('debug')

docs/features/transcripts.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,8 @@ the path instead of specifying it verbatim, or we can escape the slashes::
146146
invisible, you can add a regular expression to match them, so that you can
147147
see where they are when you look at the transcript::
148148

149-
(Cmd) set prompt
150-
prompt: (Cmd)/ /
149+
(Cmd) set editor
150+
editor: vim/ /
151151

152152
Some terminal emulators strip trailing space when you copy text from them.
153153
This could make the actual data generated by your app different than the

examples/scripts/save_help_text.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def main() -> None:
6060

6161
# Make sure we have access to self
6262
if 'self' not in globals():
63-
print("Run 'set locals_in_py true' and then rerun this script")
63+
print("Re-run this script from a cmd2 application where locals_in_py is True")
6464
return
6565

6666
# Make sure the user passed in an output file

0 commit comments

Comments
 (0)