From eee6bf15805fa8ed3ca713a4c6e8edfd9ebc5d4e Mon Sep 17 00:00:00 2001 From: Kevin Van Brunt Date: Tue, 19 Nov 2019 22:24:13 -0500 Subject: Added capability to override the argument parser class used by cmd2 built-in commands --- cmd2/__init__.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'cmd2/__init__.py') diff --git a/cmd2/__init__.py b/cmd2/__init__.py index 8e8a8845..8fc5e9f2 100644 --- a/cmd2/__init__.py +++ b/cmd2/__init__.py @@ -11,7 +11,17 @@ except DistributionNotFound: pass from .ansi import style -from .argparse_custom import Cmd2ArgumentParser, CompletionError, CompletionItem +from .argparse_custom import Cmd2ArgumentParser, CompletionError, CompletionItem, set_default_argument_parser + +# Check if user has defined a module that sets a custom value for argparse_custom.DEFAULT_ARGUMENT_PARSER +import argparse +cmd2_parser_module = getattr(argparse, 'cmd2_parser_module', None) +if cmd2_parser_module is not None: + import importlib + importlib.import_module(cmd2_parser_module) + +# Get the current value for argparse_custom.DEFAULT_ARGUMENT_PARSER +from .argparse_custom import DEFAULT_ARGUMENT_PARSER from .cmd2 import Cmd, EmptyStatement from .constants import COMMAND_NAME, DEFAULT_SHORTCUTS from .decorators import categorize, with_argument_list, with_argparser, with_argparser_and_unknown_args, with_category -- cgit v1.2.1