File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2828 set_default_argument_parser ,
2929)
3030
31- # Check if user has defined a module that sets a custom value for argparse_custom.DEFAULT_ARGUMENT_PARSER
31+ # Check if user has defined a module that sets a custom value for argparse_custom.DEFAULT_ARGUMENT_PARSER.
32+ # Do this before loading cmd2.Cmd class so its commands use the custom parser.
3233import argparse
3334
3435cmd2_parser_module = getattr (argparse , 'cmd2_parser_module' , None )
3738
3839 importlib .import_module (cmd2_parser_module )
3940
40- from .argparse_completer import DEFAULT_COMMAND_COMPLETER , set_default_command_completer_type
41+ from .argparse_completer import set_default_command_completer_type
4142
42- # Get the current value for argparse_custom.DEFAULT_ARGUMENT_PARSER
43- from .argparse_custom import DEFAULT_ARGUMENT_PARSER
4443from .cmd2 import Cmd
4544from .command_definition import CommandSet , with_default_category
4645from .constants import COMMAND_NAME , DEFAULT_SHORTCUTS
5453
5554__all__ : List [str ] = [
5655 'COMMAND_NAME' ,
57- 'DEFAULT_ARGUMENT_PARSER' ,
58- 'DEFAULT_COMMAND_COMPLETER' ,
5956 'DEFAULT_SHORTCUTS' ,
6057 # ANSI Style exports
6158 'bg' ,
Original file line number Diff line number Diff line change @@ -247,28 +247,26 @@ def test_apcustom_required_options():
247247
248248
249249def test_override_parser ():
250+ """Test overriding argparse_custom.DEFAULT_ARGUMENT_PARSER"""
250251 import importlib
251252
252253 from cmd2 import (
253- DEFAULT_ARGUMENT_PARSER ,
254+ argparse_custom ,
254255 )
255256
256257 # The standard parser is Cmd2ArgumentParser
257- assert DEFAULT_ARGUMENT_PARSER == Cmd2ArgumentParser
258+ assert argparse_custom . DEFAULT_ARGUMENT_PARSER == Cmd2ArgumentParser
258259
259260 # Set our parser module and force a reload of cmd2 so it loads the module
260261 argparse .cmd2_parser_module = 'examples.custom_parser'
261262 importlib .reload (cmd2 )
262- from cmd2 import (
263- DEFAULT_ARGUMENT_PARSER ,
264- )
265263
266264 # Verify DEFAULT_ARGUMENT_PARSER is now our CustomParser
267265 from examples .custom_parser import (
268266 CustomParser ,
269267 )
270268
271- assert DEFAULT_ARGUMENT_PARSER == CustomParser
269+ assert argparse_custom . DEFAULT_ARGUMENT_PARSER == CustomParser
272270
273271
274272def test_apcustom_metavar_tuple ():
You can’t perform that action at this time.
0 commit comments