diff options
| author | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2021-08-23 14:02:19 -0400 |
|---|---|---|
| committer | anselor <anselor@gmail.com> | 2021-08-23 14:17:12 -0400 |
| commit | 9d818100f3b6dfa647e58b8a0df182ea6729a197 (patch) | |
| tree | b3b9418f1e9be97e066fa85069bee2de1ad1a34a | |
| parent | 70846b510ded509666712460401c00550dfbdfcf (diff) | |
| download | cmd2-git-9d818100f3b6dfa647e58b8a0df182ea6729a197.tar.gz | |
Removed DEFAULT_ARGUMENT_PARSER and DEFAULT_COMMAND_COMPLETER from __init.py__
| -rw-r--r-- | cmd2/__init__.py | 9 | ||||
| -rw-r--r-- | tests/test_argparse_custom.py | 10 |
2 files changed, 7 insertions, 12 deletions
diff --git a/cmd2/__init__.py b/cmd2/__init__.py index 137b3115..a23b7a36 100644 --- a/cmd2/__init__.py +++ b/cmd2/__init__.py @@ -28,7 +28,8 @@ from .argparse_custom import ( set_default_argument_parser, ) -# Check if user has defined a module that sets a custom value for argparse_custom.DEFAULT_ARGUMENT_PARSER +# Check if user has defined a module that sets a custom value for argparse_custom.DEFAULT_ARGUMENT_PARSER. +# Do this before loading cmd2.Cmd class so its commands use the custom parser. import argparse cmd2_parser_module = getattr(argparse, 'cmd2_parser_module', None) @@ -37,10 +38,8 @@ if cmd2_parser_module is not None: importlib.import_module(cmd2_parser_module) -from .argparse_completer import DEFAULT_COMMAND_COMPLETER, set_default_command_completer_type +from .argparse_completer import set_default_command_completer_type -# Get the current value for argparse_custom.DEFAULT_ARGUMENT_PARSER -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 @@ -54,8 +53,6 @@ from .utils import categorize, CompletionMode, CustomCompletionSettings, Settabl __all__: List[str] = [ 'COMMAND_NAME', - 'DEFAULT_ARGUMENT_PARSER', - 'DEFAULT_COMMAND_COMPLETER', 'DEFAULT_SHORTCUTS', # ANSI Style exports 'bg', diff --git a/tests/test_argparse_custom.py b/tests/test_argparse_custom.py index dcfb7d9f..fccccd43 100644 --- a/tests/test_argparse_custom.py +++ b/tests/test_argparse_custom.py @@ -247,28 +247,26 @@ def test_apcustom_required_options(): def test_override_parser(): + """Test overriding argparse_custom.DEFAULT_ARGUMENT_PARSER""" import importlib from cmd2 import ( - DEFAULT_ARGUMENT_PARSER, + argparse_custom, ) # The standard parser is Cmd2ArgumentParser - assert DEFAULT_ARGUMENT_PARSER == Cmd2ArgumentParser + assert argparse_custom.DEFAULT_ARGUMENT_PARSER == Cmd2ArgumentParser # Set our parser module and force a reload of cmd2 so it loads the module argparse.cmd2_parser_module = 'examples.custom_parser' importlib.reload(cmd2) - from cmd2 import ( - DEFAULT_ARGUMENT_PARSER, - ) # Verify DEFAULT_ARGUMENT_PARSER is now our CustomParser from examples.custom_parser import ( CustomParser, ) - assert DEFAULT_ARGUMENT_PARSER == CustomParser + assert argparse_custom.DEFAULT_ARGUMENT_PARSER == CustomParser def test_apcustom_metavar_tuple(): |
