diff options
author | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2019-07-07 21:45:52 -0400 |
---|---|---|
committer | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2019-07-07 21:45:52 -0400 |
commit | bb2dd69bd04f5dccff9474c018eb6b6eea74c6af (patch) | |
tree | 543f626a84ac96d97c478e4e1af185ce07831908 /cmd2/cmd2.py | |
parent | f8db8b766540920de6c85a26a6740170455b9354 (diff) | |
download | cmd2-git-bb2dd69bd04f5dccff9474c018eb6b6eea74c6af.tar.gz |
Moved all custom argparse classes intended for normal development to argparse_custom.py.
Lazy loading AutoCompleter in cmd2 instance methods to allow argparse_completer.py to import
cmd2.Cmd class. This Architecture makes more sense because AutoCompleter depends on cmd2.Cmd.
Diffstat (limited to 'cmd2/cmd2.py')
-rw-r--r-- | cmd2/cmd2.py | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/cmd2/cmd2.py b/cmd2/cmd2.py index bfda6ae2..0d14d5ad 100644 --- a/cmd2/cmd2.py +++ b/cmd2/cmd2.py @@ -46,8 +46,7 @@ from . import ansi from . import constants from . import plugin from . import utils -from .argparse_completer import AutoCompleter, CompletionItem -from .argparse_custom import Cmd2ArgParser +from .argparse_custom import Cmd2ArgParser, CompletionItem from .clipboard import can_clip, get_paste_buffer, write_to_paste_buffer from .history import History, HistoryItem from .parsing import StatementParser, Statement, Macro, MacroArg, shlex_split @@ -1582,6 +1581,7 @@ class Cmd(cmd.Cmd): def _autocomplete_default(self, text: str, line: str, begidx: int, endidx: int, argparser: argparse.ArgumentParser) -> List[str]: """Default completion function for argparse commands""" + from .argparse_completer import AutoCompleter completer = AutoCompleter(argparser, self) tokens, _ = self.tokens_for_completion(line, begidx, endidx) return completer.complete_command(tokens, text, line, begidx, endidx) @@ -2643,6 +2643,7 @@ class Cmd(cmd.Cmd): # Check if this is a command with an argparse function func = self.cmd_func(command) if func and hasattr(func, 'argparser'): + from .argparse_completer import AutoCompleter completer = AutoCompleter(getattr(func, 'argparser'), self) matches = completer.complete_command_help(tokens[cmd_index:], text, line, begidx, endidx) @@ -2673,6 +2674,7 @@ class Cmd(cmd.Cmd): # If the command function uses argparse, then use argparse's help if func and hasattr(func, 'argparser'): + from .argparse_completer import AutoCompleter completer = AutoCompleter(getattr(func, 'argparser'), self) tokens = [args.command] + args.subcommand self.poutput(completer.format_help(tokens)) |