Skip to content

Commit a3511a6

Browse files
committed
Merge branch 'master' into history
2 parents 0abcb70 + 086d4db commit a3511a6

14 files changed

+50
-30
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.9.9 (TBD, 2019)
2+
* Bug Fixes
3+
* Fixed bug where the ``set`` command was not tab completing from the current ``settable`` dictionary.
4+
15
## 0.9.8 (February 06, 2019)
26
* Bug Fixes
37
* Fixed issue with echoing strings in StdSim. Because they were being sent to a binary buffer, line buffering

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,12 +242,14 @@ class CmdLineApp(cmd2.Cmd):
242242
self.multiline_commands = ['orate']
243243
self.maxrepeats = 3
244244

245-
# Add stuff to settable and shortcuts before calling base class initializer
246-
self.settable['maxrepeats'] = 'max repetitions for speak command'
245+
# Add stuff to shortcuts before calling base class initializer
247246
self.shortcuts.update({'&': 'speak'})
248247

249248
# Set use_ipython to True to enable the "ipy" command which embeds and interactive IPython shell
250249
super().__init__(use_ipython=False)
250+
251+
# Make maxrepeats settable at runtime
252+
self.settable['maxrepeats'] = 'max repetitions for speak command'
251253

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

cmd2/cmd2.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
# setting is True
3232
import argparse
3333
import cmd
34-
import collections
3534
import glob
3635
import inspect
3736
import os
@@ -328,7 +327,6 @@ class Cmd(cmd.Cmd):
328327
timing = False # Prints elapsed time for each command
329328

330329
# To make an attribute settable with the "do_set" command, add it to this ...
331-
# This starts out as a dictionary but gets converted to an OrderedDict sorted alphabetically by key
332330
settable = {'colors': 'Allow colorized output (valid values: Terminal, Always, Never)',
333331
'continuation_prompt': 'On 2nd+ line of input',
334332
'debug': 'Show full error stack on error',
@@ -539,13 +537,10 @@ def visible_prompt(self) -> str:
539537
return utils.strip_ansi(self.prompt)
540538

541539
def _finalize_app_parameters(self) -> None:
542-
"""Finalize the shortcuts and settable parameters."""
540+
"""Finalize the shortcuts"""
543541
# noinspection PyUnresolvedReferences
544542
self.shortcuts = sorted(self.shortcuts.items(), reverse=True)
545543

546-
# Make sure settable parameters are sorted alphabetically by key
547-
self.settable = collections.OrderedDict(sorted(self.settable.items(), key=lambda t: t[0]))
548-
549544
def decolorized_write(self, fileobj: IO, msg: str) -> None:
550545
"""Write a string to a fileobject, stripping ANSI escape sequences if necessary
551546
@@ -1581,13 +1576,17 @@ def get_visible_commands(self) -> List[str]:
15811576
return commands
15821577

15831578
def get_alias_names(self) -> List[str]:
1584-
"""Return a list of alias names."""
1579+
"""Return list of current alias names"""
15851580
return list(self.aliases)
15861581

15871582
def get_macro_names(self) -> List[str]:
1588-
"""Return a list of macro names."""
1583+
"""Return list of current macro names"""
15891584
return list(self.macros)
15901585

1586+
def get_settable_names(self) -> List[str]:
1587+
"""Return list of current settable names"""
1588+
return list(self.settable)
1589+
15911590
def get_commands_aliases_and_macros_for_completion(self) -> List[str]:
15921591
"""Return a list of visible commands, aliases, and macros for tab completion"""
15931592
visible_commands = set(self.get_visible_commands())
@@ -2814,7 +2813,7 @@ def show(self, args: argparse.Namespace, parameter: str='') -> None:
28142813
set_parser.add_argument('-a', '--all', action='store_true', help='display read-only settings as well')
28152814
set_parser.add_argument('-l', '--long', action='store_true', help='describe function of parameter')
28162815
setattr(set_parser.add_argument('param', nargs='?', help='parameter to set or view'),
2817-
ACTION_ARG_CHOICES, settable)
2816+
ACTION_ARG_CHOICES, get_settable_names)
28182817
set_parser.add_argument('value', nargs='?', help='the new value for settable')
28192818

28202819
@with_argparser(set_parser)

examples/cmd_as_argument.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,15 @@ def __init__(self):
3333
self.multiline_commands = ['orate']
3434
self.maxrepeats = 3
3535

36-
# Add stuff to settable and shortcuts before calling base class initializer
37-
self.settable['maxrepeats'] = 'max repetitions for speak command'
36+
# Add stuff to shortcuts before calling base class initializer
3837
self.shortcuts.update({'&': 'speak'})
3938

4039
# Set use_ipython to True to enable the "ipy" command which embeds and interactive IPython shell
4140
super().__init__(use_ipython=False)
4241

42+
# Make maxrepeats settable at runtime
43+
self.settable['maxrepeats'] = 'max repetitions for speak command'
44+
4345
speak_parser = argparse.ArgumentParser()
4446
speak_parser.add_argument('-p', '--piglatin', action='store_true', help='atinLay')
4547
speak_parser.add_argument('-s', '--shout', action='store_true', help='N00B EMULATION MODE')

examples/colors.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,15 @@ def __init__(self):
6666
self.multiline_commands = ['orate']
6767
self.maxrepeats = 3
6868

69-
# Add stuff to settable and shortcuts before calling base class initializer
70-
self.settable['maxrepeats'] = 'max repetitions for speak command'
69+
# Add stuff to shortcuts before calling base class initializer
7170
self.shortcuts.update({'&': 'speak'})
7271

7372
# Set use_ipython to True to enable the "ipy" command which embeds and interactive IPython shell
7473
super().__init__(use_ipython=True)
7574

75+
# Make maxrepeats settable at runtime
76+
self.settable['maxrepeats'] = 'max repetitions for speak command'
77+
7678
speak_parser = argparse.ArgumentParser()
7779
speak_parser.add_argument('-p', '--piglatin', action='store_true', help='atinLay')
7880
speak_parser.add_argument('-s', '--shout', action='store_true', help='N00B EMULATION MODE')

examples/decorator_example.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ def __init__(self, ip_addr=None, port=None, transcript_files=None):
2323
self.shortcuts.update({'&': 'speak'})
2424
self.maxrepeats = 3
2525

26-
# Add stuff to settable and/or shortcuts before calling base class initializer
27-
self.settable['maxrepeats'] = 'Max number of `--repeat`s allowed'
28-
2926
# Set use_ipython to True to enable the "ipy" command which embeds and interactive IPython shell
3027
super().__init__(use_ipython=False, transcript_files=transcript_files)
3128

29+
# Make maxrepeats settable at runtime
30+
self.settable['maxrepeats'] = 'Max number of `--repeat`s allowed'
31+
3232
# Disable cmd's usage of command-line arguments as commands to be run at invocation
3333
# self.allow_cli_args = False
3434

examples/environment.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ class EnvironmentApp(cmd2.Cmd):
1414
sunny = False
1515

1616
def __init__(self):
17+
super().__init__()
1718
self.settable.update({'degrees_c': 'Temperature in Celsius'})
1819
self.settable.update({'sunny': 'Is it sunny outside?'})
19-
super().__init__()
2020

2121
def do_sunbathe(self, arg):
2222
if self.degrees_c < 20:

examples/example.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,15 @@ def __init__(self):
3030
self.multiline_commands = ['orate']
3131
self.maxrepeats = 3
3232

33-
# Add stuff to settable and shortcuts before calling base class initializer
34-
self.settable['maxrepeats'] = 'max repetitions for speak command'
33+
# Add stuff to shortcuts before calling base class initializer
3534
self.shortcuts.update({'&': 'speak'})
3635

3736
# Set use_ipython to True to enable the "ipy" command which embeds and interactive IPython shell
3837
super().__init__(use_ipython=False)
3938

39+
# Make maxrepeats settable at runtime
40+
self.settable['maxrepeats'] = 'max repetitions for speak command'
41+
4042
speak_parser = argparse.ArgumentParser()
4143
speak_parser.add_argument('-p', '--piglatin', action='store_true', help='atinLay')
4244
speak_parser.add_argument('-s', '--shout', action='store_true', help='N00B EMULATION MODE')

examples/pirate.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,15 @@ def __init__(self):
3232
self.terminators = self.terminators + ['...']
3333
self.songcolor = Fore.BLUE
3434

35-
# Add stuff to settable and/or shortcuts before calling base class initializer
36-
self.settable['songcolor'] = 'Color to ``sing`` in (black/red/green/yellow/blue/magenta/cyan/white)'
35+
# Add stuff to shortcuts before calling base class initializer
3736
self.shortcuts.update({'~': 'sing'})
3837

3938
"""Initialize the base class as well as this one"""
4039
super().__init__()
40+
41+
# Make songcolor settable at runtime
42+
self.settable['songcolor'] = 'Color to ``sing`` in (black/red/green/yellow/blue/magenta/cyan/white)'
43+
4144
# prompts and defaults
4245
self.gold = 0
4346
self.initial_gold = self.gold

examples/plumbum_colors.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,15 @@ def __init__(self):
6969
self.multiline_commands = ['orate']
7070
self.maxrepeats = 3
7171

72-
# Add stuff to settable and shortcuts before calling base class initializer
73-
self.settable['maxrepeats'] = 'max repetitions for speak command'
72+
# Add stuff to shortcuts before calling base class initializer
7473
self.shortcuts.update({'&': 'speak'})
7574

7675
# Set use_ipython to True to enable the "ipy" command which embeds and interactive IPython shell
7776
super().__init__(use_ipython=True)
7877

78+
# Make maxrepeats settable at runtime
79+
self.settable['maxrepeats'] = 'max repetitions for speak command'
80+
7981
speak_parser = argparse.ArgumentParser()
8082
speak_parser.add_argument('-p', '--piglatin', action='store_true', help='atinLay')
8183
speak_parser.add_argument('-s', '--shout', action='store_true', help='N00B EMULATION MODE')

0 commit comments

Comments
 (0)