Skip to content

Commit 086d4db

Browse files
authored
Merge pull request #627 from python-cmd2/tab_settables
Tab settables
2 parents d8ae68b + 7218eb4 commit 086d4db

File tree

12 files changed

+46
-21
lines changed

12 files changed

+46
-21
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: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1599,13 +1599,17 @@ def get_visible_commands(self) -> List[str]:
15991599
return commands
16001600

16011601
def get_alias_names(self) -> List[str]:
1602-
"""Return a list of alias names."""
1602+
"""Return list of current alias names"""
16031603
return list(self.aliases)
16041604

16051605
def get_macro_names(self) -> List[str]:
1606-
"""Return a list of macro names."""
1606+
"""Return list of current macro names"""
16071607
return list(self.macros)
16081608

1609+
def get_settable_names(self) -> List[str]:
1610+
"""Return list of current settable names"""
1611+
return list(self.settable)
1612+
16091613
def get_commands_aliases_and_macros_for_completion(self) -> List[str]:
16101614
"""Return a list of visible commands, aliases, and macros for tab completion"""
16111615
visible_commands = set(self.get_visible_commands())
@@ -2832,7 +2836,7 @@ def show(self, args: argparse.Namespace, parameter: str='') -> None:
28322836
set_parser.add_argument('-a', '--all', action='store_true', help='display read-only settings as well')
28332837
set_parser.add_argument('-l', '--long', action='store_true', help='describe function of parameter')
28342838
setattr(set_parser.add_argument('param', nargs='?', help='parameter to set or view'),
2835-
ACTION_ARG_CHOICES, settable)
2839+
ACTION_ARG_CHOICES, get_settable_names)
28362840
set_parser.add_argument('value', nargs='?', help='the new value for settable')
28372841

28382842
@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')

tests/test_cmd2.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1849,6 +1849,9 @@ def test_get_macro_names(base_app):
18491849
assert len(base_app.macros) == 2
18501850
assert sorted(base_app.get_macro_names()) == ['bar', 'foo']
18511851

1852+
def test_get_settable_names(base_app):
1853+
assert sorted(base_app.get_settable_names()) == sorted(base_app.settable.keys())
1854+
18521855
def test_alias_no_subcommand(base_app, capsys):
18531856
out = run_cmd(base_app, 'alias')
18541857
assert "Usage: alias [-h]" in out[0]

tests/test_transcript.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,11 @@ def __init__(self, *args, **kwargs):
3232
self.multiline_commands = ['orate']
3333
self.maxrepeats = 3
3434

35-
# Add stuff to settable and/or shortcuts before calling base class initializer
35+
super().__init__(*args, **kwargs)
36+
37+
# Make maxrepeats settable at runtime
3638
self.settable['maxrepeats'] = 'Max number of `--repeat`s allowed'
3739

38-
super().__init__(*args, **kwargs)
3940
self.intro = 'This is an intro banner ...'
4041

4142
speak_parser = argparse.ArgumentParser()

0 commit comments

Comments
 (0)