@@ -200,7 +200,7 @@ def __init__(self, completekey: str = 'tab', stdin=None, stdout=None, *,
200
200
self .max_completion_items = 50
201
201
202
202
# A dictionary mapping settable names to their Settable instance
203
- self .settables = dict ()
203
+ self .settables = dict () # type: Dict[str, Settable]
204
204
self .build_settables ()
205
205
206
206
# Use as prompt for multiline commands on the 2nd+ line of input
@@ -220,7 +220,7 @@ def __init__(self, completekey: str = 'tab', stdin=None, stdout=None, *,
220
220
self .exclude_from_history = ['eof' , 'history' ]
221
221
222
222
# Dictionary of macro names and their values
223
- self .macros = dict ()
223
+ self .macros = dict () # type: Dict[str, Macro]
224
224
225
225
# Keeps track of typed command history in the Python shell
226
226
self ._py_history = []
@@ -249,14 +249,14 @@ def __init__(self, completekey: str = 'tab', stdin=None, stdout=None, *,
249
249
self .last_result = None
250
250
251
251
# Used by run_script command to store current script dir as a LIFO queue to support _relative_run_script command
252
- self ._script_dir = []
252
+ self ._script_dir = [] # type: List[str]
253
253
254
254
# Context manager used to protect critical sections in the main thread from stopping due to a KeyboardInterrupt
255
255
self .sigint_protection = utils .ContextFlag ()
256
256
257
257
# If the current command created a process to pipe to, then this will be a ProcReader object.
258
258
# Otherwise it will be None. It's used to know when a pipe process can be killed and/or waited upon.
259
- self ._cur_pipe_proc_reader = None
259
+ self ._cur_pipe_proc_reader = None # type: Optional[utils.ProcReader]
260
260
261
261
# Used to keep track of whether we are redirecting or piping output
262
262
self ._redirecting = False
@@ -280,7 +280,7 @@ def __init__(self, completekey: str = 'tab', stdin=None, stdout=None, *,
280
280
self .broken_pipe_warning = ''
281
281
282
282
# Commands that will run at the beginning of the command loop
283
- self ._startup_commands = []
283
+ self ._startup_commands = [] # type: List[str]
284
284
285
285
# If a startup script is provided and exists, then execute it in the startup commands
286
286
if startup_script :
@@ -289,7 +289,7 @@ def __init__(self, completekey: str = 'tab', stdin=None, stdout=None, *,
289
289
self ._startup_commands .append ("run_script {}" .format (utils .quote_string (startup_script )))
290
290
291
291
# Transcript files to run instead of interactive command loop
292
- self ._transcript_files = None
292
+ self ._transcript_files = None # type: Optional[List[str]]
293
293
294
294
# Check for command line args
295
295
if allow_cli_args :
@@ -333,7 +333,7 @@ def __init__(self, completekey: str = 'tab', stdin=None, stdout=None, *,
333
333
# Commands that have been disabled from use. This is to support commands that are only available
334
334
# during specific states of the application. This dictionary's keys are the command names and its
335
335
# values are DisabledCommand objects.
336
- self .disabled_commands = dict ()
336
+ self .disabled_commands = dict () # type: Dict[str, DisabledCommand]
337
337
338
338
# If any command has been categorized, then all other commands that haven't been categorized
339
339
# will display under this section in the help output.
@@ -1910,7 +1910,7 @@ def _redirect_output(self, statement: Statement) -> utils.RedirectionSavedState:
1910
1910
self ._cur_pipe_proc_reader , self ._redirecting )
1911
1911
1912
1912
# The ProcReader for this command
1913
- cmd_pipe_proc_reader = None
1913
+ cmd_pipe_proc_reader = None # type: Optional[utils.ProcReader]
1914
1914
1915
1915
if not self .allow_redirection :
1916
1916
# Don't return since we set some state variables at the end of the function
@@ -2694,16 +2694,31 @@ def do_help(self, args: argparse.Namespace) -> None:
2694
2694
2695
2695
def _help_menu (self , verbose : bool = False ) -> None :
2696
2696
"""Show a list of commands which help can be displayed for"""
2697
+ cmds_cats , cmds_doc , cmds_undoc , help_topics = self ._build_command_info ()
2698
+
2699
+ if len (cmds_cats ) == 0 :
2700
+ # No categories found, fall back to standard behavior
2701
+ self .poutput ("{}" .format (str (self .doc_leader )))
2702
+ self ._print_topics (self .doc_header , cmds_doc , verbose )
2703
+ else :
2704
+ # Categories found, Organize all commands by category
2705
+ self .poutput ('{}' .format (str (self .doc_leader )))
2706
+ self .poutput ('{}' .format (str (self .doc_header )), end = "\n \n " )
2707
+ for category in sorted (cmds_cats .keys (), key = self .default_sort_key ):
2708
+ self ._print_topics (category , cmds_cats [category ], verbose )
2709
+ self ._print_topics (self .default_category , cmds_doc , verbose )
2710
+
2711
+ self .print_topics (self .misc_header , help_topics , 15 , 80 )
2712
+ self .print_topics (self .undoc_header , cmds_undoc , 15 , 80 )
2713
+
2714
+ def _build_command_info (self ):
2697
2715
# Get a sorted list of help topics
2698
2716
help_topics = sorted (self .get_help_topics (), key = self .default_sort_key )
2699
-
2700
2717
# Get a sorted list of visible command names
2701
2718
visible_commands = sorted (self .get_visible_commands (), key = self .default_sort_key )
2702
-
2703
2719
cmds_doc = []
2704
2720
cmds_undoc = []
2705
2721
cmds_cats = {}
2706
-
2707
2722
for command in visible_commands :
2708
2723
func = self .cmd_func (command )
2709
2724
has_help_func = False
@@ -2724,21 +2739,7 @@ def _help_menu(self, verbose: bool = False) -> None:
2724
2739
cmds_doc .append (command )
2725
2740
else :
2726
2741
cmds_undoc .append (command )
2727
-
2728
- if len (cmds_cats ) == 0 :
2729
- # No categories found, fall back to standard behavior
2730
- self .poutput ("{}" .format (str (self .doc_leader )))
2731
- self ._print_topics (self .doc_header , cmds_doc , verbose )
2732
- else :
2733
- # Categories found, Organize all commands by category
2734
- self .poutput ('{}' .format (str (self .doc_leader )))
2735
- self .poutput ('{}' .format (str (self .doc_header )), end = "\n \n " )
2736
- for category in sorted (cmds_cats .keys (), key = self .default_sort_key ):
2737
- self ._print_topics (category , cmds_cats [category ], verbose )
2738
- self ._print_topics (self .default_category , cmds_doc , verbose )
2739
-
2740
- self .print_topics (self .misc_header , help_topics , 15 , 80 )
2741
- self .print_topics (self .undoc_header , cmds_undoc , 15 , 80 )
2742
+ return cmds_cats , cmds_doc , cmds_undoc , help_topics
2742
2743
2743
2744
def _print_topics (self , header : str , cmds : List [str ], verbose : bool ) -> None :
2744
2745
"""Customized version of print_topics that can switch between verbose or traditional output"""
0 commit comments