summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin Van Brunt <kmvanbrunt@gmail.com>2021-11-22 10:49:39 -0500
committerKevin Van Brunt <kmvanbrunt@gmail.com>2021-11-22 11:06:28 -0500
commit7cc025901dba5f76b080b4da2355f6fa19ebf4db (patch)
treece07abb9e17e767606fbec3023f637f6a0e2528b
parent087c2066076e55c5f8200c0c6127bcd389aae67b (diff)
downloadcmd2-git-ns_fix.tar.gz
Fixed issue where a ns_provider could be passed None instead of its correct cmd2.Cmd or CommandSet value.ns_fix
-rw-r--r--CHANGELOG.md4
-rw-r--r--cmd2/decorators.py8
2 files changed, 8 insertions, 4 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index e32dd4af..0f231fec 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,7 @@
+## 2.3.2 (November 22, 2021)
+* Bug Fixes
+ * Fixed issue where a `ns_provider` could be passed `None` instead of its correct `cmd2.Cmd` or `CommandSet` value.
+
## 2.3.1 (November 18, 2021)
* Bug Fixes
* Fixed issue introduced in 2.3.0 with `AlternatingTable`, `BorderedTable`, and `SimpleTable` that caused
diff --git a/cmd2/decorators.py b/cmd2/decorators.py
index 1ff0bdbe..c06142fb 100644
--- a/cmd2/decorators.py
+++ b/cmd2/decorators.py
@@ -276,9 +276,9 @@ def with_argparser(
with the given instance of argparse.ArgumentParser.
: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 ns_provider: An optional function that accepts a cmd2.Cmd or cmd2.CommandSet 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
:param with_unknown_args: if true, then capture unknown args
:return: function that gets passed argparse-parsed args in a ``Namespace``
@@ -351,7 +351,7 @@ def with_argparser(
# functions are registered with the command argparser before anything is instantiated, we
# need to find an instance at runtime that matches the types during declaration
provider_self = cmd2_app._resolve_func_self(ns_provider, args[0])
- namespace = ns_provider(provider_self if not None else cmd2_app)
+ namespace = ns_provider(provider_self if provider_self is not None else cmd2_app)
try:
new_args: Union[Tuple[argparse.Namespace], Tuple[argparse.Namespace, List[str]]]