22# flake8: noqa C901
33# NOTE: Ignoring flake8 cyclomatic complexity in this file
44"""
5- This module defines the AutoCompleter class which provides argparse-based tab completion to cmd2 apps.
5+ This module defines the ArgparseCompleter class which provides argparse-based tab completion to cmd2 apps.
66See the header of argparse_custom.py for instructions on how to use these features.
77"""
88
@@ -64,7 +64,7 @@ def _looks_like_flag(token: str, parser: argparse.ArgumentParser) -> bool:
6464
6565
6666# noinspection PyProtectedMember
67- class AutoCompleter :
67+ class ArgparseCompleter :
6868 """Automatic command line tab completion based on argparse parameters"""
6969
7070 class _ArgumentState :
@@ -103,12 +103,12 @@ def __init__(self, arg_action: argparse.Action) -> None:
103103 def __init__ (self , parser : argparse .ArgumentParser , cmd2_app : cmd2 .Cmd , * ,
104104 parent_tokens : Optional [Dict [str , List [str ]]] = None ) -> None :
105105 """
106- Create an AutoCompleter
106+ Create an ArgparseCompleter
107107
108108 :param parser: ArgumentParser instance
109- :param cmd2_app: reference to the Cmd2 application that owns this AutoCompleter
109+ :param cmd2_app: reference to the Cmd2 application that owns this ArgparseCompleter
110110 :param parent_tokens: optional dictionary mapping parent parsers' arg names to their tokens
111- this is only used by AutoCompleter when recursing on subcommand parsers
111+ This is only used by ArgparseCompleter when recursing on subcommand parsers
112112 Defaults to None
113113 """
114114 self ._parser = parser
@@ -167,7 +167,7 @@ def complete_command(self, tokens: List[str], text: str, line: str, begidx: int,
167167 # Completed mutually exclusive groups
168168 completed_mutex_groups = dict () # dict(argparse._MutuallyExclusiveGroup -> Action which completed group)
169169
170- def consume_argument (arg_state : AutoCompleter ._ArgumentState ) -> None :
170+ def consume_argument (arg_state : ArgparseCompleter ._ArgumentState ) -> None :
171171 """Consuming token as an argument"""
172172 arg_state .count += 1
173173 consumed_arg_values .setdefault (arg_state .action .dest , [])
@@ -286,7 +286,7 @@ def update_mutex_groups(arg_action: argparse.Action) -> bool:
286286 # earlier in the command line. Reset them now for this use of it.
287287 consumed_arg_values [action .dest ] = []
288288
289- new_arg_state = AutoCompleter ._ArgumentState (action )
289+ new_arg_state = ArgparseCompleter ._ArgumentState (action )
290290
291291 # Keep track of this flag if it can receive arguments
292292 if new_arg_state .max > 0 :
@@ -319,16 +319,16 @@ def update_mutex_groups(arg_action: argparse.Action) -> bool:
319319 if action .dest != argparse .SUPPRESS :
320320 parent_tokens [action .dest ] = [token ]
321321
322- completer = AutoCompleter (self ._subcommand_action .choices [token ], self ._cmd2_app ,
323- parent_tokens = parent_tokens )
322+ completer = ArgparseCompleter (self ._subcommand_action .choices [token ], self ._cmd2_app ,
323+ parent_tokens = parent_tokens )
324324 return completer .complete_command (tokens [token_index :], text , line , begidx , endidx )
325325 else :
326326 # Invalid subcommand entered, so no way to complete remaining tokens
327327 return []
328328
329329 # Otherwise keep track of the argument
330330 else :
331- pos_arg_state = AutoCompleter ._ArgumentState (action )
331+ pos_arg_state = ArgparseCompleter ._ArgumentState (action )
332332
333333 # Check if we have a positional to consume this token
334334 if pos_arg_state is not None :
@@ -393,7 +393,7 @@ def update_mutex_groups(arg_action: argparse.Action) -> bool:
393393 # If we aren't current tracking a positional, then get the next positional arg to handle this token
394394 if pos_arg_state is None :
395395 action = remaining_positionals .popleft ()
396- pos_arg_state = AutoCompleter ._ArgumentState (action )
396+ pos_arg_state = ArgparseCompleter ._ArgumentState (action )
397397
398398 try :
399399 completion_results = self ._complete_for_arg (pos_arg_state .action , text , line ,
@@ -483,11 +483,11 @@ def complete_subcommand_help(self, tokens: List[str], text: str, line: str, begi
483483 :return: List of subcommand completions
484484 """
485485 # If our parser has subcommands, we must examine the tokens and check if they are subcommands
486- # If so, we will let the subcommand's parser handle the rest of the tokens via another AutoCompleter .
486+ # If so, we will let the subcommand's parser handle the rest of the tokens via another ArgparseCompleter .
487487 if self ._subcommand_action is not None :
488488 for token_index , token in enumerate (tokens [1 :], start = 1 ):
489489 if token in self ._subcommand_action .choices :
490- completer = AutoCompleter (self ._subcommand_action .choices [token ], self ._cmd2_app )
490+ completer = ArgparseCompleter (self ._subcommand_action .choices [token ], self ._cmd2_app )
491491 return completer .complete_subcommand_help (tokens [token_index :], text , line , begidx , endidx )
492492 elif token_index == len (tokens ) - 1 :
493493 # Since this is the last token, we will attempt to complete it
@@ -503,11 +503,11 @@ def format_help(self, tokens: List[str]) -> str:
503503 :return: help text of the command being queried
504504 """
505505 # If our parser has subcommands, we must examine the tokens and check if they are subcommands
506- # If so, we will let the subcommand's parser handle the rest of the tokens via another AutoCompleter .
506+ # If so, we will let the subcommand's parser handle the rest of the tokens via another ArgparseCompleter .
507507 if self ._subcommand_action is not None :
508508 for token_index , token in enumerate (tokens [1 :], start = 1 ):
509509 if token in self ._subcommand_action .choices :
510- completer = AutoCompleter (self ._subcommand_action .choices [token ], self ._cmd2_app )
510+ completer = ArgparseCompleter (self ._subcommand_action .choices [token ], self ._cmd2_app )
511511 return completer .format_help (tokens [token_index :])
512512 else :
513513 break
0 commit comments