-
Notifications
You must be signed in to change notification settings - Fork 130
Tab settables #627
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tab settables #627
Changes from all commits
3cf43e1
10f6b1d
5d49abe
6e4d480
6cb882e
7218eb4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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()) | ||
|
|
@@ -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) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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' | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider adding a unit test to validate that
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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') | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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): | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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] | ||
|
|
||
There was a problem hiding this comment.
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.settablecan now be modified at an arbitrary time and is no loner restricted to being modified prior to callingsuper.__init__().There was a problem hiding this comment.
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.