Skip to content

Commit d68b3fe

Browse files
committed
Updated CHANGELOG and made some more methods protected
1 parent 52ea5e4 commit d68b3fe

File tree

3 files changed

+26
-22
lines changed

3 files changed

+26
-22
lines changed

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1-
## 0.9.14 (TBD, 2019
1+
## 0.9.14 (TBD, 2019)
22
* Enhancements
33
* Added support for and testing with Python 3.8, starting with 3.8 beta
44
* Breaking Changes
55
* Python 3.4 reached its [end of life](https://www.python.org/dev/peps/pep-0429/) on March 18, 2019 and is no longer supported by `cmd2`
6+
* If you need to use Python 3.4, you should pin your requirements to use `cmd2` 0.9.13
7+
* Made lots of changes to minimize the public API of the `cmd2.Cmd` class
8+
* Attributes and methods we do not intend to be public now all begin with an underscore
9+
* We make no API stability guarantees about these internal functions
610
* **Renamed Commands Notice**
711
* The following commands have been renamed. The old names will be supported until the next release.
812
* load --> run_script

cmd2/cmd2.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1516,7 +1516,7 @@ def _complete_worker(self, text: str, state: int) -> Optional[str]:
15161516
else:
15171517
# Complete token against anything a user can run
15181518
self._completion_matches = self.basic_complete(text, line, begidx, endidx,
1519-
self.get_commands_aliases_and_macros_for_completion())
1519+
self._get_commands_aliases_and_macros_for_completion())
15201520

15211521
# Handle single result
15221522
if len(self._completion_matches) == 1:
@@ -1593,23 +1593,23 @@ def get_visible_commands(self) -> List[str]:
15931593

15941594
return commands
15951595

1596-
def get_alias_names(self) -> List[str]:
1596+
def _get_alias_names(self) -> List[str]:
15971597
"""Return list of current alias names"""
15981598
return list(self.aliases)
15991599

1600-
def get_macro_names(self) -> List[str]:
1600+
def _get_macro_names(self) -> List[str]:
16011601
"""Return list of current macro names"""
16021602
return list(self.macros)
16031603

1604-
def get_settable_names(self) -> List[str]:
1604+
def _get_settable_names(self) -> List[str]:
16051605
"""Return list of current settable names"""
16061606
return list(self.settable)
16071607

1608-
def get_commands_aliases_and_macros_for_completion(self) -> List[str]:
1608+
def _get_commands_aliases_and_macros_for_completion(self) -> List[str]:
16091609
"""Return a list of visible commands, aliases, and macros for tab completion"""
16101610
visible_commands = set(self.get_visible_commands())
1611-
alias_names = set(self.get_alias_names())
1612-
macro_names = set(self.get_macro_names())
1611+
alias_names = set(self._get_alias_names())
1612+
macro_names = set(self._get_macro_names())
16131613
return list(visible_commands | alias_names | macro_names)
16141614

16151615
def get_help_topics(self) -> List[str]:
@@ -2080,11 +2080,11 @@ def cmd_func(self, command: str) -> Optional[Callable]:
20802080
Get the function for a command
20812081
:param command: the name of the command
20822082
"""
2083-
func_name = self.cmd_func_name(command)
2083+
func_name = self._cmd_func_name(command)
20842084
if func_name:
20852085
return getattr(self, func_name)
20862086

2087-
def cmd_func_name(self, command: str) -> str:
2087+
def _cmd_func_name(self, command: str) -> str:
20882088
"""Get the method name associated with a given command.
20892089
20902090
:param command: command to look up method name which implements it
@@ -2346,7 +2346,7 @@ def _alias_list(self, args: argparse.Namespace) -> None:
23462346
epilog=alias_create_epilog)
23472347
alias_create_parser.add_argument('name', help='name of this alias')
23482348
setattr(alias_create_parser.add_argument('command', help='what the alias resolves to'),
2349-
ACTION_ARG_CHOICES, get_commands_aliases_and_macros_for_completion)
2349+
ACTION_ARG_CHOICES, _get_commands_aliases_and_macros_for_completion)
23502350
setattr(alias_create_parser.add_argument('command_args', nargs=argparse.REMAINDER,
23512351
help='arguments to pass to command'),
23522352
ACTION_ARG_CHOICES, ('path_complete',))
@@ -2358,7 +2358,7 @@ def _alias_list(self, args: argparse.Namespace) -> None:
23582358
alias_delete_parser = alias_subparsers.add_parser('delete', help=alias_delete_help,
23592359
description=alias_delete_description)
23602360
setattr(alias_delete_parser.add_argument('name', nargs='*', help='alias to delete'),
2361-
ACTION_ARG_CHOICES, get_alias_names)
2361+
ACTION_ARG_CHOICES, _get_alias_names)
23622362
alias_delete_parser.add_argument('-a', '--all', action='store_true', help="delete all aliases")
23632363
alias_delete_parser.set_defaults(func=_alias_delete)
23642364

@@ -2372,7 +2372,7 @@ def _alias_list(self, args: argparse.Namespace) -> None:
23722372
alias_list_parser = alias_subparsers.add_parser('list', help=alias_list_help,
23732373
description=alias_list_description)
23742374
setattr(alias_list_parser.add_argument('name', nargs="*", help='alias to list'),
2375-
ACTION_ARG_CHOICES, get_alias_names)
2375+
ACTION_ARG_CHOICES, _get_alias_names)
23762376
alias_list_parser.set_defaults(func=_alias_list)
23772377

23782378
# Preserve quotes since we are passing strings to other commands
@@ -2550,7 +2550,7 @@ def _macro_list(self, args: argparse.Namespace) -> None:
25502550
epilog=macro_create_epilog)
25512551
macro_create_parser.add_argument('name', help='name of this macro')
25522552
setattr(macro_create_parser.add_argument('command', help='what the macro resolves to'),
2553-
ACTION_ARG_CHOICES, get_commands_aliases_and_macros_for_completion)
2553+
ACTION_ARG_CHOICES, _get_commands_aliases_and_macros_for_completion)
25542554
setattr(macro_create_parser.add_argument('command_args', nargs=argparse.REMAINDER,
25552555
help='arguments to pass to command'),
25562556
ACTION_ARG_CHOICES, ('path_complete',))
@@ -2562,7 +2562,7 @@ def _macro_list(self, args: argparse.Namespace) -> None:
25622562
macro_delete_parser = macro_subparsers.add_parser('delete', help=macro_delete_help,
25632563
description=macro_delete_description)
25642564
setattr(macro_delete_parser.add_argument('name', nargs='*', help='macro to delete'),
2565-
ACTION_ARG_CHOICES, get_macro_names)
2565+
ACTION_ARG_CHOICES, _get_macro_names)
25662566
macro_delete_parser.add_argument('-a', '--all', action='store_true', help="delete all macros")
25672567
macro_delete_parser.set_defaults(func=_macro_delete)
25682568

@@ -2575,7 +2575,7 @@ def _macro_list(self, args: argparse.Namespace) -> None:
25752575

25762576
macro_list_parser = macro_subparsers.add_parser('list', help=macro_list_help, description=macro_list_description)
25772577
setattr(macro_list_parser.add_argument('name', nargs="*", help='macro to list'),
2578-
ACTION_ARG_CHOICES, get_macro_names)
2578+
ACTION_ARG_CHOICES, _get_macro_names)
25792579
macro_list_parser.set_defaults(func=_macro_list)
25802580

25812581
# Preserve quotes since we are passing strings to other commands
@@ -2910,7 +2910,7 @@ def _show(self, args: argparse.Namespace, parameter: str = '') -> None:
29102910
set_parser.add_argument('-a', '--all', action='store_true', help='display read-only settings as well')
29112911
set_parser.add_argument('-l', '--long', action='store_true', help='describe function of parameter')
29122912
setattr(set_parser.add_argument('param', nargs='?', help='parameter to set or view'),
2913-
ACTION_ARG_CHOICES, get_settable_names)
2913+
ACTION_ARG_CHOICES, _get_settable_names)
29142914
set_parser.add_argument('value', nargs='?', help='the new value for settable')
29152915

29162916
@with_argparser(set_parser)
@@ -3908,7 +3908,7 @@ def enable_command(self, command: str) -> None:
39083908

39093909
# Restore the command and help functions to their original values
39103910
dc = self.disabled_commands[command]
3911-
setattr(self, self.cmd_func_name(command), dc.command_function)
3911+
setattr(self, self._cmd_func_name(command), dc.command_function)
39123912

39133913
if dc.help_function is None:
39143914
delattr(self, help_func_name)
@@ -3958,7 +3958,7 @@ def disable_command(self, command: str, message_to_print: str) -> None:
39583958
# Overwrite the command and help functions to print the message
39593959
new_func = functools.partial(self._report_disabled_command_usage,
39603960
message_to_print=message_to_print.replace(COMMAND_NAME, command))
3961-
setattr(self, self.cmd_func_name(command), new_func)
3961+
setattr(self, self._cmd_func_name(command), new_func)
39623962
setattr(self, help_func_name, new_func)
39633963

39643964
def disable_category(self, category: str, message_to_print: str) -> None:

tests/test_cmd2.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1560,17 +1560,17 @@ def test_get_alias_names(base_app):
15601560
run_cmd(base_app, 'alias create fake run_pyscript')
15611561
run_cmd(base_app, 'alias create ls !ls -hal')
15621562
assert len(base_app.aliases) == 2
1563-
assert sorted(base_app.get_alias_names()) == ['fake', 'ls']
1563+
assert sorted(base_app._get_alias_names()) == ['fake', 'ls']
15641564

15651565
def test_get_macro_names(base_app):
15661566
assert len(base_app.macros) == 0
15671567
run_cmd(base_app, 'macro create foo !echo foo')
15681568
run_cmd(base_app, 'macro create bar !echo bar')
15691569
assert len(base_app.macros) == 2
1570-
assert sorted(base_app.get_macro_names()) == ['bar', 'foo']
1570+
assert sorted(base_app._get_macro_names()) == ['bar', 'foo']
15711571

15721572
def test_get_settable_names(base_app):
1573-
assert sorted(base_app.get_settable_names()) == sorted(base_app.settable.keys())
1573+
assert sorted(base_app._get_settable_names()) == sorted(base_app.settable.keys())
15741574

15751575
def test_alias_no_subcommand(base_app):
15761576
out, err = run_cmd(base_app, 'alias')

0 commit comments

Comments
 (0)