summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTodd Leonhardt <todd.leonhardt@gmail.com>2019-06-15 16:03:26 -0400
committerTodd Leonhardt <todd.leonhardt@gmail.com>2019-06-15 16:03:26 -0400
commitd68b3feb3095ec717655972c5e4dc89d7c1ed579 (patch)
treefc3ce5e426ee0d4b58dfc571b9dd8080879233ed
parent52ea5e4a6bf22a0f1dfb498b5cbe863fbc69faab (diff)
downloadcmd2-git-d68b3feb3095ec717655972c5e4dc89d7c1ed579.tar.gz
Updated CHANGELOG and made some more methods protected
-rw-r--r--CHANGELOG.md6
-rw-r--r--cmd2/cmd2.py36
-rw-r--r--tests/test_cmd2.py6
3 files changed, 26 insertions, 22 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index a66cad15..a07c5198 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,8 +1,12 @@
-## 0.9.14 (TBD, 2019
+## 0.9.14 (TBD, 2019)
* Enhancements
* Added support for and testing with Python 3.8, starting with 3.8 beta
* Breaking Changes
* 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`
+ * If you need to use Python 3.4, you should pin your requirements to use `cmd2` 0.9.13
+ * Made lots of changes to minimize the public API of the `cmd2.Cmd` class
+ * Attributes and methods we do not intend to be public now all begin with an underscore
+ * We make no API stability guarantees about these internal functions
* **Renamed Commands Notice**
* The following commands have been renamed. The old names will be supported until the next release.
* load --> run_script
diff --git a/cmd2/cmd2.py b/cmd2/cmd2.py
index 4e7a7a5d..3aa0895a 100644
--- a/cmd2/cmd2.py
+++ b/cmd2/cmd2.py
@@ -1516,7 +1516,7 @@ class Cmd(cmd.Cmd):
else:
# Complete token against anything a user can run
self._completion_matches = self.basic_complete(text, line, begidx, endidx,
- self.get_commands_aliases_and_macros_for_completion())
+ self._get_commands_aliases_and_macros_for_completion())
# Handle single result
if len(self._completion_matches) == 1:
@@ -1593,23 +1593,23 @@ class Cmd(cmd.Cmd):
return commands
- def get_alias_names(self) -> List[str]:
+ def _get_alias_names(self) -> List[str]:
"""Return list of current alias names"""
return list(self.aliases)
- def get_macro_names(self) -> List[str]:
+ def _get_macro_names(self) -> List[str]:
"""Return list of current macro names"""
return list(self.macros)
- def get_settable_names(self) -> List[str]:
+ 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]:
+ 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())
- alias_names = set(self.get_alias_names())
- macro_names = set(self.get_macro_names())
+ alias_names = set(self._get_alias_names())
+ macro_names = set(self._get_macro_names())
return list(visible_commands | alias_names | macro_names)
def get_help_topics(self) -> List[str]:
@@ -2080,11 +2080,11 @@ class Cmd(cmd.Cmd):
Get the function for a command
:param command: the name of the command
"""
- func_name = self.cmd_func_name(command)
+ func_name = self._cmd_func_name(command)
if func_name:
return getattr(self, func_name)
- def cmd_func_name(self, command: str) -> str:
+ def _cmd_func_name(self, command: str) -> str:
"""Get the method name associated with a given command.
:param command: command to look up method name which implements it
@@ -2346,7 +2346,7 @@ class Cmd(cmd.Cmd):
epilog=alias_create_epilog)
alias_create_parser.add_argument('name', help='name of this alias')
setattr(alias_create_parser.add_argument('command', help='what the alias resolves to'),
- ACTION_ARG_CHOICES, get_commands_aliases_and_macros_for_completion)
+ ACTION_ARG_CHOICES, _get_commands_aliases_and_macros_for_completion)
setattr(alias_create_parser.add_argument('command_args', nargs=argparse.REMAINDER,
help='arguments to pass to command'),
ACTION_ARG_CHOICES, ('path_complete',))
@@ -2358,7 +2358,7 @@ class Cmd(cmd.Cmd):
alias_delete_parser = alias_subparsers.add_parser('delete', help=alias_delete_help,
description=alias_delete_description)
setattr(alias_delete_parser.add_argument('name', nargs='*', help='alias to delete'),
- ACTION_ARG_CHOICES, get_alias_names)
+ ACTION_ARG_CHOICES, _get_alias_names)
alias_delete_parser.add_argument('-a', '--all', action='store_true', help="delete all aliases")
alias_delete_parser.set_defaults(func=_alias_delete)
@@ -2372,7 +2372,7 @@ class Cmd(cmd.Cmd):
alias_list_parser = alias_subparsers.add_parser('list', help=alias_list_help,
description=alias_list_description)
setattr(alias_list_parser.add_argument('name', nargs="*", help='alias to list'),
- ACTION_ARG_CHOICES, get_alias_names)
+ ACTION_ARG_CHOICES, _get_alias_names)
alias_list_parser.set_defaults(func=_alias_list)
# Preserve quotes since we are passing strings to other commands
@@ -2550,7 +2550,7 @@ class Cmd(cmd.Cmd):
epilog=macro_create_epilog)
macro_create_parser.add_argument('name', help='name of this macro')
setattr(macro_create_parser.add_argument('command', help='what the macro resolves to'),
- ACTION_ARG_CHOICES, get_commands_aliases_and_macros_for_completion)
+ ACTION_ARG_CHOICES, _get_commands_aliases_and_macros_for_completion)
setattr(macro_create_parser.add_argument('command_args', nargs=argparse.REMAINDER,
help='arguments to pass to command'),
ACTION_ARG_CHOICES, ('path_complete',))
@@ -2562,7 +2562,7 @@ class Cmd(cmd.Cmd):
macro_delete_parser = macro_subparsers.add_parser('delete', help=macro_delete_help,
description=macro_delete_description)
setattr(macro_delete_parser.add_argument('name', nargs='*', help='macro to delete'),
- ACTION_ARG_CHOICES, get_macro_names)
+ ACTION_ARG_CHOICES, _get_macro_names)
macro_delete_parser.add_argument('-a', '--all', action='store_true', help="delete all macros")
macro_delete_parser.set_defaults(func=_macro_delete)
@@ -2575,7 +2575,7 @@ class Cmd(cmd.Cmd):
macro_list_parser = macro_subparsers.add_parser('list', help=macro_list_help, description=macro_list_description)
setattr(macro_list_parser.add_argument('name', nargs="*", help='macro to list'),
- ACTION_ARG_CHOICES, get_macro_names)
+ ACTION_ARG_CHOICES, _get_macro_names)
macro_list_parser.set_defaults(func=_macro_list)
# Preserve quotes since we are passing strings to other commands
@@ -2910,7 +2910,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, get_settable_names)
+ ACTION_ARG_CHOICES, _get_settable_names)
set_parser.add_argument('value', nargs='?', help='the new value for settable')
@with_argparser(set_parser)
@@ -3908,7 +3908,7 @@ class Cmd(cmd.Cmd):
# Restore the command and help functions to their original values
dc = self.disabled_commands[command]
- setattr(self, self.cmd_func_name(command), dc.command_function)
+ setattr(self, self._cmd_func_name(command), dc.command_function)
if dc.help_function is None:
delattr(self, help_func_name)
@@ -3958,7 +3958,7 @@ class Cmd(cmd.Cmd):
# Overwrite the command and help functions to print the message
new_func = functools.partial(self._report_disabled_command_usage,
message_to_print=message_to_print.replace(COMMAND_NAME, command))
- setattr(self, self.cmd_func_name(command), new_func)
+ setattr(self, self._cmd_func_name(command), new_func)
setattr(self, help_func_name, new_func)
def disable_category(self, category: str, message_to_print: str) -> None:
diff --git a/tests/test_cmd2.py b/tests/test_cmd2.py
index c563082e..1b761306 100644
--- a/tests/test_cmd2.py
+++ b/tests/test_cmd2.py
@@ -1560,17 +1560,17 @@ def test_get_alias_names(base_app):
run_cmd(base_app, 'alias create fake run_pyscript')
run_cmd(base_app, 'alias create ls !ls -hal')
assert len(base_app.aliases) == 2
- assert sorted(base_app.get_alias_names()) == ['fake', 'ls']
+ assert sorted(base_app._get_alias_names()) == ['fake', 'ls']
def test_get_macro_names(base_app):
assert len(base_app.macros) == 0
run_cmd(base_app, 'macro create foo !echo foo')
run_cmd(base_app, 'macro create bar !echo bar')
assert len(base_app.macros) == 2
- assert sorted(base_app.get_macro_names()) == ['bar', 'foo']
+ 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())
+ assert sorted(base_app._get_settable_names()) == sorted(base_app.settable.keys())
def test_alias_no_subcommand(base_app):
out, err = run_cmd(base_app, 'alias')