summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.md4
-rwxr-xr-xREADME.md6
-rw-r--r--cmd2/cmd2.py10
-rwxr-xr-xexamples/cmd_as_argument.py6
-rwxr-xr-xexamples/colors.py6
-rwxr-xr-xexamples/decorator_example.py6
-rwxr-xr-xexamples/environment.py2
-rwxr-xr-xexamples/example.py6
-rwxr-xr-xexamples/pirate.py7
-rwxr-xr-xexamples/plumbum_colors.py6
-rw-r--r--tests/test_cmd2.py3
-rw-r--r--tests/test_transcript.py5
12 files changed, 46 insertions, 21 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index fc91dfbf..6d3b4c32 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,7 @@
+## 0.9.9 (TBD, 2019)
+* Bug Fixes
+ * Fixed bug where the ``set`` command was not tab completing from the current ``settable`` dictionary.
+
## 0.9.8 (February 06, 2019)
* Bug Fixes
* Fixed issue with echoing strings in StdSim. Because they were being sent to a binary buffer, line buffering
diff --git a/README.md b/README.md
index 97b7e72b..0480f51b 100755
--- a/README.md
+++ b/README.md
@@ -242,12 +242,14 @@ class CmdLineApp(cmd2.Cmd):
self.multiline_commands = ['orate']
self.maxrepeats = 3
- # Add stuff to settable and shortcuts before calling base class initializer
- self.settable['maxrepeats'] = 'max repetitions for speak command'
+ # Add stuff to shortcuts before calling base class initializer
self.shortcuts.update({'&': 'speak'})
# Set use_ipython to True to enable the "ipy" command which embeds and interactive IPython shell
super().__init__(use_ipython=False)
+
+ # Make maxrepeats settable at runtime
+ self.settable['maxrepeats'] = 'max repetitions for speak command'
speak_parser = argparse.ArgumentParser()
speak_parser.add_argument('-p', '--piglatin', action='store_true', help='atinLay')
diff --git a/cmd2/cmd2.py b/cmd2/cmd2.py
index 68b1f921..65435d6b 100644
--- a/cmd2/cmd2.py
+++ b/cmd2/cmd2.py
@@ -1599,13 +1599,17 @@ class Cmd(cmd.Cmd):
return commands
def get_alias_names(self) -> List[str]:
- """Return a list of alias names."""
+ """Return list of current alias names"""
return list(self.aliases)
def get_macro_names(self) -> List[str]:
- """Return a list of macro names."""
+ """Return list of current macro names"""
return list(self.macros)
+ def get_settable_names(self) -> List[str]:
+ """Return list of current settable names"""
+ return list(self.settable)
+
def get_commands_aliases_and_macros_for_completion(self) -> List[str]:
"""Return a list of visible commands, aliases, and macros for tab completion"""
visible_commands = set(self.get_visible_commands())
@@ -2832,7 +2836,7 @@ class Cmd(cmd.Cmd):
set_parser.add_argument('-a', '--all', action='store_true', help='display read-only settings as well')
set_parser.add_argument('-l', '--long', action='store_true', help='describe function of parameter')
setattr(set_parser.add_argument('param', nargs='?', help='parameter to set or view'),
- ACTION_ARG_CHOICES, settable)
+ ACTION_ARG_CHOICES, get_settable_names)
set_parser.add_argument('value', nargs='?', help='the new value for settable')
@with_argparser(set_parser)
diff --git a/examples/cmd_as_argument.py b/examples/cmd_as_argument.py
index 070a34a0..dcec81c8 100755
--- a/examples/cmd_as_argument.py
+++ b/examples/cmd_as_argument.py
@@ -33,13 +33,15 @@ class CmdLineApp(cmd2.Cmd):
self.multiline_commands = ['orate']
self.maxrepeats = 3
- # Add stuff to settable and shortcuts before calling base class initializer
- self.settable['maxrepeats'] = 'max repetitions for speak command'
+ # Add stuff to shortcuts before calling base class initializer
self.shortcuts.update({'&': 'speak'})
# Set use_ipython to True to enable the "ipy" command which embeds and interactive IPython shell
super().__init__(use_ipython=False)
+ # Make maxrepeats settable at runtime
+ self.settable['maxrepeats'] = 'max repetitions for speak command'
+
speak_parser = argparse.ArgumentParser()
speak_parser.add_argument('-p', '--piglatin', action='store_true', help='atinLay')
speak_parser.add_argument('-s', '--shout', action='store_true', help='N00B EMULATION MODE')
diff --git a/examples/colors.py b/examples/colors.py
index 2641ae44..62df54e6 100755
--- a/examples/colors.py
+++ b/examples/colors.py
@@ -66,13 +66,15 @@ class CmdLineApp(cmd2.Cmd):
self.multiline_commands = ['orate']
self.maxrepeats = 3
- # Add stuff to settable and shortcuts before calling base class initializer
- self.settable['maxrepeats'] = 'max repetitions for speak command'
+ # Add stuff to shortcuts before calling base class initializer
self.shortcuts.update({'&': 'speak'})
# Set use_ipython to True to enable the "ipy" command which embeds and interactive IPython shell
super().__init__(use_ipython=True)
+ # Make maxrepeats settable at runtime
+ self.settable['maxrepeats'] = 'max repetitions for speak command'
+
speak_parser = argparse.ArgumentParser()
speak_parser.add_argument('-p', '--piglatin', action='store_true', help='atinLay')
speak_parser.add_argument('-s', '--shout', action='store_true', help='N00B EMULATION MODE')
diff --git a/examples/decorator_example.py b/examples/decorator_example.py
index bd9228db..5d127619 100755
--- a/examples/decorator_example.py
+++ b/examples/decorator_example.py
@@ -23,12 +23,12 @@ class CmdLineApp(cmd2.Cmd):
self.shortcuts.update({'&': 'speak'})
self.maxrepeats = 3
- # Add stuff to settable and/or shortcuts before calling base class initializer
- self.settable['maxrepeats'] = 'Max number of `--repeat`s allowed'
-
# Set use_ipython to True to enable the "ipy" command which embeds and interactive IPython shell
super().__init__(use_ipython=False, transcript_files=transcript_files)
+ # Make maxrepeats settable at runtime
+ self.settable['maxrepeats'] = 'Max number of `--repeat`s allowed'
+
# Disable cmd's usage of command-line arguments as commands to be run at invocation
# self.allow_cli_args = False
diff --git a/examples/environment.py b/examples/environment.py
index c45ce71c..e899cce8 100755
--- a/examples/environment.py
+++ b/examples/environment.py
@@ -14,9 +14,9 @@ class EnvironmentApp(cmd2.Cmd):
sunny = False
def __init__(self):
+ super().__init__()
self.settable.update({'degrees_c': 'Temperature in Celsius'})
self.settable.update({'sunny': 'Is it sunny outside?'})
- super().__init__()
def do_sunbathe(self, arg):
if self.degrees_c < 20:
diff --git a/examples/example.py b/examples/example.py
index 264abd84..04727ec6 100755
--- a/examples/example.py
+++ b/examples/example.py
@@ -30,13 +30,15 @@ class CmdLineApp(cmd2.Cmd):
self.multiline_commands = ['orate']
self.maxrepeats = 3
- # Add stuff to settable and shortcuts before calling base class initializer
- self.settable['maxrepeats'] = 'max repetitions for speak command'
+ # Add stuff to shortcuts before calling base class initializer
self.shortcuts.update({'&': 'speak'})
# Set use_ipython to True to enable the "ipy" command which embeds and interactive IPython shell
super().__init__(use_ipython=False)
+ # Make maxrepeats settable at runtime
+ self.settable['maxrepeats'] = 'max repetitions for speak command'
+
speak_parser = argparse.ArgumentParser()
speak_parser.add_argument('-p', '--piglatin', action='store_true', help='atinLay')
speak_parser.add_argument('-s', '--shout', action='store_true', help='N00B EMULATION MODE')
diff --git a/examples/pirate.py b/examples/pirate.py
index 2da3fcaa..32330404 100755
--- a/examples/pirate.py
+++ b/examples/pirate.py
@@ -32,12 +32,15 @@ class Pirate(cmd2.Cmd):
self.terminators = self.terminators + ['...']
self.songcolor = Fore.BLUE
- # Add stuff to settable and/or shortcuts before calling base class initializer
- self.settable['songcolor'] = 'Color to ``sing`` in (black/red/green/yellow/blue/magenta/cyan/white)'
+ # Add stuff to shortcuts before calling base class initializer
self.shortcuts.update({'~': 'sing'})
"""Initialize the base class as well as this one"""
super().__init__()
+
+ # Make songcolor settable at runtime
+ self.settable['songcolor'] = 'Color to ``sing`` in (black/red/green/yellow/blue/magenta/cyan/white)'
+
# prompts and defaults
self.gold = 0
self.initial_gold = self.gold
diff --git a/examples/plumbum_colors.py b/examples/plumbum_colors.py
index 0cea3c10..3e5031d7 100755
--- a/examples/plumbum_colors.py
+++ b/examples/plumbum_colors.py
@@ -69,13 +69,15 @@ class CmdLineApp(cmd2.Cmd):
self.multiline_commands = ['orate']
self.maxrepeats = 3
- # Add stuff to settable and shortcuts before calling base class initializer
- self.settable['maxrepeats'] = 'max repetitions for speak command'
+ # Add stuff to shortcuts before calling base class initializer
self.shortcuts.update({'&': 'speak'})
# Set use_ipython to True to enable the "ipy" command which embeds and interactive IPython shell
super().__init__(use_ipython=True)
+ # Make maxrepeats settable at runtime
+ self.settable['maxrepeats'] = 'max repetitions for speak command'
+
speak_parser = argparse.ArgumentParser()
speak_parser.add_argument('-p', '--piglatin', action='store_true', help='atinLay')
speak_parser.add_argument('-s', '--shout', action='store_true', help='N00B EMULATION MODE')
diff --git a/tests/test_cmd2.py b/tests/test_cmd2.py
index 630a8fa0..09c4fa6c 100644
--- a/tests/test_cmd2.py
+++ b/tests/test_cmd2.py
@@ -1849,6 +1849,9 @@ def test_get_macro_names(base_app):
assert len(base_app.macros) == 2
assert sorted(base_app.get_macro_names()) == ['bar', 'foo']
+def test_get_settable_names(base_app):
+ assert sorted(base_app.get_settable_names()) == sorted(base_app.settable.keys())
+
def test_alias_no_subcommand(base_app, capsys):
out = run_cmd(base_app, 'alias')
assert "Usage: alias [-h]" in out[0]
diff --git a/tests/test_transcript.py b/tests/test_transcript.py
index d7438e86..6bfe187e 100644
--- a/tests/test_transcript.py
+++ b/tests/test_transcript.py
@@ -32,10 +32,11 @@ class CmdLineApp(cmd2.Cmd):
self.multiline_commands = ['orate']
self.maxrepeats = 3
- # Add stuff to settable and/or shortcuts before calling base class initializer
+ super().__init__(*args, **kwargs)
+
+ # Make maxrepeats settable at runtime
self.settable['maxrepeats'] = 'Max number of `--repeat`s allowed'
- super().__init__(*args, **kwargs)
self.intro = 'This is an intro banner ...'
speak_parser = argparse.ArgumentParser()