Skip to content

Commit c7ac2e9

Browse files
authored
Merge pull request #873 from python-cmd2/set_update
Updated set command to support tab completion of values
2 parents 60a212c + c4893ea commit c7ac2e9

34 files changed

+426
-295
lines changed

CHANGELOG.md

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
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
4+
* Added `add_settable()` and `remove_settable()` convenience methods to update `self.settable` dictionary
45
* Breaking changes
56
* Renamed `locals_in_py` attribute of `cmd2.Cmd` to `self_in_py`
67
* The following public attributes of `cmd2.Cmd` are no longer settable at runtime by default:
78
* `continuation_prompt`
89
* `self_in_py`
910
* `prompt`
10-
11+
* `self.settable` changed to `self.settables`
12+
* 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
15+
* **set** command now supports tab-completion of values
16+
* Removed `cast()` utility function
17+
1118
## 0.9.25 (January 26, 2020)
1219
* Enhancements
1320
* Reduced what gets put in package downloadable from PyPI (removed irrelevant CI config files and such)
@@ -69,7 +76,7 @@
6976
* Fix bug where cmd2 ran 'stty sane' command when stdin was not a terminal
7077
* Enhancements
7178
* Send all startup script paths to run_script. Previously we didn't do this if the file was empty, but that
72-
showed no record of the run_script command in history.
79+
showed no record of the run_script command in history.
7380
* Made it easier for developers to override `edit` command by having `do_history` no longer call `do_edit`. This
7481
also removes the need to exclude `edit` command from history list.
7582
* It is no longer necessary to set the `prog` attribute of an argparser with subcommands. cmd2 now automatically
@@ -138,7 +145,7 @@
138145
* Enhancements
139146
* Greatly simplified using argparse-based tab completion. The new interface is a complete overhaul that breaks
140147
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)
141-
for more information.
148+
for more information.
142149
* Enabled tab completion on multiline commands
143150
* **Renamed Commands Notice**
144151
* The following commands were renamed in the last release and have been removed in this release
@@ -148,7 +155,7 @@
148155
* We apologize for any inconvenience, but the new names are more self-descriptive
149156
* Lots of end users were confused particularly about what exactly `load` should be loading
150157
* Breaking Changes
151-
* 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)
152159
* Since it can be useful for creating [post-parsing hooks](https://cmd2.readthedocs.io/en/latest/features/hooks.html#postparsing-hooks)
153160
* Completely overhauled the interface for adding tab completion to argparse arguments. See enhancements for more details.
154161
* `ACArgumentParser` is now called `Cmd2ArgumentParser`
@@ -188,7 +195,7 @@
188195
* `perror` - print a message to sys.stderr
189196
* `pexcept` - print Exception message to sys.stderr. If debug is true, print exception traceback if one exists
190197
* Signature of `poutput` and `perror` significantly changed
191-
* 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`
192199
* 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
193200
* `end` argument is now keyword-only and cannot be specified positionally
194201
* `traceback_war` no longer exists as an argument since it isn't needed now that `perror` and `pexcept` exist
@@ -198,7 +205,7 @@
198205
* `COLORS_NEVER` --> `ANSI_NEVER`
199206
* `COLORS_TERMINAL` --> `ANSI_TERMINAL`
200207
* **Renamed Commands Notice**
201-
* 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.
202209
* `load` --> `run_script`
203210
* `_relative_load` --> `_relative_run_script`
204211
* `pyscript` --> `run_pyscript`
@@ -217,7 +224,7 @@
217224
* Fixed issue where `_cmdloop()` suppressed exceptions by returning from within its `finally` code
218225
* Fixed UnsupportedOperation on fileno error when a shell command was one of the commands run while generating
219226
a transcript
220-
* 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
221228
* Enhancements
222229
* **Added capability to chain pipe commands and redirect their output (e.g. !ls -l | grep user | wc -l > out.txt)**
223230
* `pyscript` limits a command's stdout capture to the same period that redirection does.
@@ -238,7 +245,7 @@
238245
* Text scripts now run immediately instead of adding their commands to `cmdqueue`. This allows easy capture of
239246
the entire script's output.
240247
* Added member to `CommandResult` called `stop` which is the return value of `onecmd_plus_hooks` after it runs
241-
the given command line.
248+
the given command line.
242249
* Breaking changes
243250
* Replaced `unquote_redirection_tokens()` with `unquote_specific_tokens()`. This was to support the fix
244251
that allows terminators in alias and macro values.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ class CmdLineApp(cmd2.Cmd):
248248
super().__init__(use_ipython=False, multiline_commands=['orate'], shortcuts=shortcuts)
249249

250250
# Make maxrepeats settable at runtime
251-
self.settable['maxrepeats'] = 'max repetitions for speak command'
251+
self.add_settable(cmd2.Settable('maxrepeats', int, 'max repetitions for speak command'))
252252

253253
speak_parser = argparse.ArgumentParser()
254254
speak_parser.add_argument('-p', '--piglatin', action='store_true', help='atinLay')

cmd2/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,4 @@
2727
from .decorators import categorize, with_argument_list, with_argparser, with_argparser_and_unknown_args, with_category
2828
from .parsing import Statement
2929
from .py_bridge import CommandResult
30+
from .utils import Settable

cmd2/argparse_completer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,10 @@ def _looks_like_flag(token: str, parser: argparse.ArgumentParser) -> bool:
6464

6565

6666
# noinspection PyProtectedMember
67-
class AutoCompleter(object):
67+
class AutoCompleter:
6868
"""Automatic command line tab completion based on argparse parameters"""
6969

70-
class _ArgumentState(object):
70+
class _ArgumentState:
7171
"""Keeps state of an argument being parsed"""
7272

7373
def __init__(self, arg_action: argparse.Action) -> None:

0 commit comments

Comments
 (0)