Skip to content

Commit

Permalink
Removed DEFAULT_ARGUMENT_PARSER and DEFAULT_COMMAND_COMPLETER from __…
Browse files Browse the repository at this point in the history
…init.py__
  • Loading branch information
kmvanbrunt authored and anselor committed Aug 23, 2021
1 parent 70846b5 commit 9d81810
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 12 deletions.
9 changes: 3 additions & 6 deletions cmd2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
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)
Expand All @@ -37,10 +38,8 @@

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
Expand All @@ -54,8 +53,6 @@

__all__: List[str] = [
'COMMAND_NAME',
'DEFAULT_ARGUMENT_PARSER',
'DEFAULT_COMMAND_COMPLETER',
'DEFAULT_SHORTCUTS',
# ANSI Style exports
'bg',
Expand Down
10 changes: 4 additions & 6 deletions tests/test_argparse_custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down

0 comments on commit 9d81810

Please sign in to comment.