@@ -1486,10 +1486,10 @@ def complete(self, text: str, state: int) -> Optional[str]:
14861486
14871487 if compfunc is None :
14881488 # There's no completer function, next see if the command uses argparser
1489- cmd_func = self ._cmd_func (command )
1490- if cmd_func and hasattr (cmd_func , 'argparser' ):
1489+ func = self .cmd_func (command )
1490+ if func and hasattr (func , 'argparser' ):
14911491 compfunc = functools .partial (self ._autocomplete_default ,
1492- argparser = getattr (cmd_func , 'argparser' ))
1492+ argparser = getattr (func , 'argparser' ))
14931493 else :
14941494 compfunc = self .completedefault
14951495
@@ -1970,17 +1970,16 @@ def _restore_output(self, statement: Statement) -> None:
19701970
19711971 self .redirecting = False
19721972
1973- def _cmd_func (self , command : str ) -> Optional [Callable ]:
1973+ def cmd_func (self , command : str ) -> Optional [Callable ]:
19741974 """
19751975 Get the function for a command
19761976 :param command: the name of the command
19771977 """
1978- func_name = self ._cmd_func_name (command )
1978+ func_name = self .cmd_func_name (command )
19791979 if func_name :
19801980 return getattr (self , func_name )
1981- return None
19821981
1983- def _cmd_func_name (self , command : str ) -> str :
1982+ def cmd_func_name (self , command : str ) -> str :
19841983 """Get the method name associated with a given command.
19851984
19861985 :param command: command to look up method name which implements it
@@ -2006,9 +2005,9 @@ def onecmd(self, statement: Union[Statement, str]) -> bool:
20062005 if statement .command in self .macros :
20072006 stop = self ._run_macro (statement )
20082007 else :
2009- cmd_func = self ._cmd_func (statement .command )
2010- if cmd_func :
2011- stop = cmd_func (statement )
2008+ func = self .cmd_func (statement .command )
2009+ if func :
2010+ stop = func (statement )
20122011
20132012 # Since we have a valid command store it in the history
20142013 if statement .command not in self .exclude_from_history :
@@ -2588,10 +2587,10 @@ def complete_help_subcommand(self, text: str, line: str, begidx: int, endidx: in
25882587 matches = []
25892588
25902589 # Check if this is a command with an argparse function
2591- cmd_func = self ._cmd_func (command )
2592- if cmd_func and hasattr (cmd_func , 'argparser' ):
2593- completer = AutoCompleter (getattr (cmd_func , 'argparser' ), cmd2_app = self )
2594- matches = completer .complete_command_help (tokens [cmd_index :], text , line , begidx , endidx )
2590+ func = self .cmd_func (command )
2591+ if func and hasattr (func , 'argparser' ):
2592+ completer = AutoCompleter (getattr (func , 'argparser' ), cmd2_app = self )
2593+ matches = completer .complete_command_help (tokens [cmd_index :], text , line , begidx , endidx )
25952594
25962595 return matches
25972596
@@ -2611,21 +2610,15 @@ def do_help(self, args: argparse.Namespace) -> None:
26112610 if not args .command or args .verbose :
26122611 self ._help_menu (args .verbose )
26132612
2614- elif args . command :
2613+ else :
26152614 # Getting help for a specific command
2616- cmd_func = self ._cmd_func (args .command )
2617- if cmd_func :
2618- # Check to see if this function was decorated with an argparse ArgumentParser
2619- if hasattr (cmd_func , 'argparser' ):
2620- completer = AutoCompleter (getattr (cmd_func , 'argparser' ), cmd2_app = self )
2621- tokens = [args .command ]
2622- tokens .extend (args .subcommand )
2623- self .poutput (completer .format_help (tokens ))
2624- else :
2625- # No special behavior needed, delegate to cmd base class do_help()
2626- super ().do_help (args .command )
2615+ func = self .cmd_func (args .command )
2616+ if func and hasattr (func , 'argparser' ):
2617+ completer = AutoCompleter (getattr (func , 'argparser' ), cmd2_app = self )
2618+ tokens = [args .command ] + args .subcommand
2619+ self .poutput (completer .format_help (tokens ))
26272620 else :
2628- # This could be a help topic
2621+ # No special behavior needed, delegate to cmd base class do_help()
26292622 super ().do_help (args .command )
26302623
26312624 def _help_menu (self , verbose : bool = False ) -> None :
@@ -2642,12 +2635,12 @@ def _help_menu(self, verbose: bool=False) -> None:
26422635 cmds_cats = {}
26432636
26442637 for command in visible_commands :
2645- cmd_func = self ._cmd_func (command )
2646- if command in help_topics or cmd_func .__doc__ :
2638+ func = self .cmd_func (command )
2639+ if command in help_topics or func .__doc__ :
26472640 if command in help_topics :
26482641 help_topics .remove (command )
2649- if hasattr (cmd_func , HELP_CATEGORY ):
2650- category = getattr (cmd_func , HELP_CATEGORY )
2642+ if hasattr (func , HELP_CATEGORY ):
2643+ category = getattr (func , HELP_CATEGORY )
26512644 cmds_cats .setdefault (category , [])
26522645 cmds_cats [category ].append (command )
26532646 else :
@@ -2700,13 +2693,13 @@ def _print_topics(self, header: str, cmds: List[str], verbose: bool) -> None:
27002693 func = getattr (self , 'help_' + command )
27012694 except AttributeError :
27022695 # Couldn't find a help function
2703- cmd_func = self ._cmd_func (command )
2696+ func = self .cmd_func (command )
27042697 try :
27052698 # Now see if help_summary has been set
2706- doc = cmd_func .help_summary
2699+ doc = func .help_summary
27072700 except AttributeError :
27082701 # Last, try to directly access the function's doc-string
2709- doc = cmd_func .__doc__
2702+ doc = func .__doc__
27102703 else :
27112704 # we found the help function
27122705 result = io .StringIO ()
0 commit comments