summaryrefslogtreecommitdiff
path: root/cmd2/argparse_custom.py
diff options
context:
space:
mode:
authorKevin Van Brunt <kmvanbrunt@gmail.com>2021-08-31 16:41:44 -0400
committerKevin Van Brunt <kmvanbrunt@gmail.com>2021-08-31 16:50:29 -0400
commita28976d5d85ecff164ee653df2f5b801336eebe6 (patch)
treece6d0387bec68d393fa5b2ab8718c2ddf490f4f4 /cmd2/argparse_custom.py
parent631038db4d5baacf37e12dd1664239fd2b4143e7 (diff)
downloadcmd2-git-custom_completer_refactor.tar.gz
Added ap_completer_type arg to Cmd2ArgumentParser.__init__().custom_completer_refactor
Added unit tests for custom ArgparseCompleter
Diffstat (limited to 'cmd2/argparse_custom.py')
-rw-r--r--cmd2/argparse_custom.py11
1 files changed, 11 insertions, 0 deletions
diff --git a/cmd2/argparse_custom.py b/cmd2/argparse_custom.py
index dd4db570..b33dd95c 100644
--- a/cmd2/argparse_custom.py
+++ b/cmd2/argparse_custom.py
@@ -1252,7 +1252,16 @@ class Cmd2ArgumentParser(argparse.ArgumentParser):
conflict_handler: str = 'error',
add_help: bool = True,
allow_abbrev: bool = True,
+ *,
+ ap_completer_type: Optional[Type['ArgparseCompleter']] = None,
) -> None:
+ """
+ # Custom parameter added by cmd2
+
+ :param ap_completer_type: optional parameter which specifies a subclass of ArgparseCompleter for custom tab completion
+ behavior on this parser. If this is None or not present, then cmd2 will use
+ argparse_completer.DEFAULT_AP_COMPLETER when tab completing this parser's arguments
+ """
super(Cmd2ArgumentParser, self).__init__(
prog=prog,
usage=usage,
@@ -1268,6 +1277,8 @@ class Cmd2ArgumentParser(argparse.ArgumentParser):
allow_abbrev=allow_abbrev,
)
+ self.set_ap_completer_type(ap_completer_type) # type: ignore[attr-defined]
+
# noinspection PyProtectedMember
def add_subparsers(self, **kwargs: Any) -> argparse._SubParsersAction:
"""