Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.9.9 (TBD, 2019)
* Bug Fixes
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd recommend adding an Enhancement section and mentioning that self.settable can now be modified at an arbitrary time and is no loner restricted to being modified prior to calling super.__init__().

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was always possible, I just updated the examples to reflect it.

* 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
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
10 changes: 7 additions & 3 deletions cmd2/cmd2.py
Original file line number Diff line number Diff line change
Expand Up @@ -1599,13 +1599,17 @@ def get_visible_commands(self) -> List[str]:
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())
Expand Down Expand Up @@ -2832,7 +2836,7 @@ def show(self, args: argparse.Namespace, parameter: str='') -> None:
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)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice little fix

set_parser.add_argument('value', nargs='?', help='the new value for settable')

@with_argparser(set_parser)
Expand Down
6 changes: 4 additions & 2 deletions examples/cmd_as_argument.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,15 @@ def __init__(self):
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'
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding a unit test to validate that self.settable can be mutated either before or after calling super.__init__().

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was always possible, I just updated the examples to reflect it.


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')
Expand Down
6 changes: 4 additions & 2 deletions examples/colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,15 @@ def __init__(self):
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')
Expand Down
6 changes: 3 additions & 3 deletions examples/decorator_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ def __init__(self, ip_addr=None, port=None, transcript_files=None):
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

Expand Down
2 changes: 1 addition & 1 deletion examples/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 4 additions & 2 deletions examples/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,15 @@ def __init__(self):
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')
Expand Down
7 changes: 5 additions & 2 deletions examples/pirate.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,15 @@ def __init__(self):
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
Expand Down
6 changes: 4 additions & 2 deletions examples/plumbum_colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,15 @@ def __init__(self):
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')
Expand Down
3 changes: 3 additions & 0 deletions tests/test_cmd2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding a unit test

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]
Expand Down
5 changes: 3 additions & 2 deletions tests/test_transcript.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,11 @@ def __init__(self, *args, **kwargs):
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()
Expand Down