summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin Van Brunt <kmvanbrunt@gmail.com>2021-01-22 16:15:41 -0500
committerKevin Van Brunt <kmvanbrunt@gmail.com>2021-01-22 16:15:41 -0500
commit4bdb20a1419f104637aecd5194c643a82412e035 (patch)
tree4f38e3195eead417e81312d7f56c6d7b995e38b3
parentb2c7113bc74c802bc8822dd1f0659339e8147380 (diff)
downloadcmd2-git-4bdb20a1419f104637aecd5194c643a82412e035.tar.gz
Removed with_argparser_and_unknown_args since it was deprecated in 1.3.0.
-rw-r--r--CHANGELOG.md1
-rw-r--r--cmd2/__init__.py3
-rw-r--r--cmd2/decorators.py43
-rw-r--r--tests/test_argparse.py2
-rwxr-xr-xtests/test_completion.py2
5 files changed, 4 insertions, 47 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index da6c5e9b..f3b6c0df 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -10,6 +10,7 @@
* ``Namespace.__statement__`` has been removed. Use `Namespace.cmd2_statement.get()` instead.
* Removed `--silent` flag from `alias/macro create` since startup scripts can be run silently.
* Removed `--with_silent` flag from `alias/macro list` since startup scripts can be run silently.
+ * Removed `with_argparser_and_unknown_args` since it was deprecated in 1.3.0.
* Enhancements
* Added support for custom tab completion and up-arrow input history to `cmd2.Cmd2.read_input`.
See [read_input.py](https://github.com/python-cmd2/cmd2/blob/master/examples/read_input.py)
diff --git a/cmd2/__init__.py b/cmd2/__init__.py
index f507dc28..a4bbfc41 100644
--- a/cmd2/__init__.py
+++ b/cmd2/__init__.py
@@ -30,8 +30,7 @@ from .argparse_custom import DEFAULT_ARGUMENT_PARSER
from .cmd2 import Cmd
from .command_definition import CommandSet, with_default_category
from .constants import COMMAND_NAME, DEFAULT_SHORTCUTS
-from .decorators import with_argument_list, with_argparser, with_argparser_and_unknown_args, with_category, \
- as_subcommand_to
+from .decorators import with_argument_list, with_argparser, with_category, as_subcommand_to
from .exceptions import Cmd2ArgparseError, CommandSetRegistrationError, CompletionError, SkipPostcommandHooks
from . import plugin
from .parsing import Statement
diff --git a/cmd2/decorators.py b/cmd2/decorators.py
index 6d99b848..f204bad9 100644
--- a/cmd2/decorators.py
+++ b/cmd2/decorators.py
@@ -188,49 +188,6 @@ def _set_parser_prog(parser: argparse.ArgumentParser, prog: str):
break
-def with_argparser_and_unknown_args(parser: argparse.ArgumentParser, *,
- ns_provider: Optional[Callable[..., argparse.Namespace]] = None,
- preserve_quotes: bool = False) -> \
- Callable[[argparse.Namespace, List], Optional[bool]]:
- """
- Deprecated decorator. Use `with_argparser(parser, with_unknown_args=True)` instead.
-
- A decorator to alter a cmd2 method to populate its ``args`` argument by parsing
- arguments with the given instance of argparse.ArgumentParser, but also returning
- unknown args as a list.
-
- :param parser: unique instance of ArgumentParser
- :param ns_provider: An optional function that accepts a cmd2.Cmd object as an argument
- and returns an argparse.Namespace. This is useful if the Namespace
- needs to be prepopulated with state data that affects parsing.
- :param preserve_quotes: if ``True``, then arguments passed to argparse maintain their quotes
- :return: function that gets passed argparse-parsed args in a ``Namespace`` and a list
- of unknown argument strings. A :class:`cmd2.argparse_custom.Cmd2AttributeWrapper` called
- ``cmd2_statement`` is included in the ``Namespace`` to provide access to the :class:`cmd2.Statement`
- object. that was created when parsing the command line. This can be useful if the command function
- needs to know the command line.
-
- :Example:
-
- >>> parser = argparse.ArgumentParser()
- >>> parser.add_argument('-p', '--piglatin', action='store_true', help='atinLay')
- >>> parser.add_argument('-s', '--shout', action='store_true', help='N00B EMULATION MODE')
- >>> parser.add_argument('-r', '--repeat', type=int, help='output [n] times')
- >>>
- >>> class MyApp(cmd2.Cmd):
- >>> @cmd2.with_argparser(parser, with_unknown_args=True)
- >>> def do_argprint(self, args, unknown):
- >>> "Print the options and argument list this options command was called with."
- >>> self.poutput('args: {!r}'.format(args))
- >>> self.poutput('unknowns: {}'.format(unknown))
- """
- import warnings
- warnings.warn('This decorator will be deprecated. Use `with_argparser(parser, with_unknown_args=True)`.',
- PendingDeprecationWarning, stacklevel=2)
-
- return with_argparser(parser, ns_provider=ns_provider, preserve_quotes=preserve_quotes, with_unknown_args=True)
-
-
def with_argparser(parser: argparse.ArgumentParser, *,
ns_provider: Optional[Callable[..., argparse.Namespace]] = None,
preserve_quotes: bool = False,
diff --git a/tests/test_argparse.py b/tests/test_argparse.py
index e7806056..72d9ae92 100644
--- a/tests/test_argparse.py
+++ b/tests/test_argparse.py
@@ -195,7 +195,7 @@ def test_argparser_correct_args_with_quotes_and_midline_options(argparse_app):
def test_argparser_and_unknown_args_kwargs(argparse_app, capsys):
- """Test with_argparser_and_unknown_args wrapper passes through kwargs to command function"""
+ """Test with_argparser wrapper passing through kwargs to command function"""
argparse_app.do_speak('', keyword_arg="foo")
out, err = capsys.readouterr()
assert out == "foo\n"
diff --git a/tests/test_completion.py b/tests/test_completion.py
index 2f4e34c3..3eab8572 100755
--- a/tests/test_completion.py
+++ b/tests/test_completion.py
@@ -1155,7 +1155,7 @@ class SubcommandsWithUnknownExample(cmd2.Cmd):
@pytest.fixture
def scu_app():
- """Declare test fixture for with_argparser_and_unknown_args"""
+ """Declare test fixture for with_argparser decorator"""
app = SubcommandsWithUnknownExample()
return app