@@ -60,13 +60,13 @@ def _build_hint(parser: argparse.ArgumentParser, arg_action: argparse.Action) ->
60
60
suppress_hint = arg_action .get_suppress_tab_hint () # type: ignore[attr-defined]
61
61
if suppress_hint or arg_action .help == argparse .SUPPRESS :
62
62
return ''
63
- else :
64
- # Use the parser's help formatter to display just this action's help text
65
- formatter = parser ._get_formatter ()
66
- formatter .start_section ("Hint" )
67
- formatter .add_argument (arg_action )
68
- formatter .end_section ()
69
- return formatter .format_help ()
63
+
64
+ # Use the parser's help formatter to display just this action's help text
65
+ formatter = parser ._get_formatter ()
66
+ formatter .start_section ("Hint" )
67
+ formatter .add_argument (arg_action )
68
+ formatter .end_section ()
69
+ return formatter .format_help ()
70
70
71
71
72
72
def _single_prefix_char (token : str , parser : argparse .ArgumentParser ) -> bool :
@@ -274,7 +274,7 @@ def update_mutex_groups(arg_action: argparse.Action) -> None:
274
274
for group_action in group ._group_actions :
275
275
if group_action == arg_action :
276
276
continue
277
- elif group_action in self ._flag_to_action .values ():
277
+ if group_action in self ._flag_to_action .values ():
278
278
matched_flags .extend (group_action .option_strings )
279
279
elif group_action in remaining_positionals :
280
280
remaining_positionals .remove (group_action )
@@ -292,15 +292,15 @@ def update_mutex_groups(arg_action: argparse.Action) -> None:
292
292
continue
293
293
294
294
# If we're in a flag REMAINDER arg, force all future tokens to go to that until a double dash is hit
295
- elif flag_arg_state is not None and flag_arg_state .is_remainder :
295
+ if flag_arg_state is not None and flag_arg_state .is_remainder :
296
296
if token == '--' :
297
297
flag_arg_state = None
298
298
else :
299
299
consume_argument (flag_arg_state )
300
300
continue
301
301
302
302
# Handle '--' which tells argparse all remaining arguments are non-flags
303
- elif token == '--' and not skip_remaining_flags :
303
+ if token == '--' and not skip_remaining_flags :
304
304
# Check if there is an unfinished flag
305
305
if (
306
306
flag_arg_state is not None
@@ -310,10 +310,9 @@ def update_mutex_groups(arg_action: argparse.Action) -> None:
310
310
raise _UnfinishedFlagError (flag_arg_state )
311
311
312
312
# Otherwise end the current flag
313
- else :
314
- flag_arg_state = None
315
- skip_remaining_flags = True
316
- continue
313
+ flag_arg_state = None
314
+ skip_remaining_flags = True
315
+ continue
317
316
318
317
# Check the format of the current token to see if it can be an argument's value
319
318
if _looks_like_flag (token , self ._parser ) and not skip_remaining_flags :
@@ -393,13 +392,11 @@ def update_mutex_groups(arg_action: argparse.Action) -> None:
393
392
return completer .complete (
394
393
text , line , begidx , endidx , tokens [token_index + 1 :], cmd_set = cmd_set
395
394
)
396
- else :
397
- # Invalid subcommand entered, so no way to complete remaining tokens
398
- return []
395
+ # Invalid subcommand entered, so no way to complete remaining tokens
396
+ return []
399
397
400
398
# Otherwise keep track of the argument
401
- else :
402
- pos_arg_state = _ArgumentState (action )
399
+ pos_arg_state = _ArgumentState (action )
403
400
404
401
# Check if we have a positional to consume this token
405
402
if pos_arg_state is not None :
@@ -452,7 +449,7 @@ def update_mutex_groups(arg_action: argparse.Action) -> None:
452
449
return completion_results
453
450
454
451
# Otherwise, print a hint if the flag isn't finished or text isn't possibly the start of a flag
455
- elif (
452
+ if (
456
453
(isinstance (flag_arg_state .min , int ) and flag_arg_state .count < flag_arg_state .min )
457
454
or not _single_prefix_char (text , self ._parser )
458
455
or skip_remaining_flags
@@ -478,7 +475,7 @@ def update_mutex_groups(arg_action: argparse.Action) -> None:
478
475
return completion_results
479
476
480
477
# Otherwise, print a hint if text isn't possibly the start of a flag
481
- elif not _single_prefix_char (text , self ._parser ) or skip_remaining_flags :
478
+ if not _single_prefix_char (text , self ._parser ) or skip_remaining_flags :
482
479
raise _NoResultsError (self ._parser , pos_arg_state .action )
483
480
484
481
# If we aren't skipping remaining flags, then complete flag names if either is True:
@@ -620,11 +617,10 @@ def complete_subcommand_help(self, text: str, line: str, begidx: int, endidx: in
620
617
621
618
completer = completer_type (parser , self ._cmd2_app )
622
619
return completer .complete_subcommand_help (text , line , begidx , endidx , tokens [token_index + 1 :])
623
- elif token_index == len (tokens ) - 1 :
620
+ if token_index == len (tokens ) - 1 :
624
621
# Since this is the last token, we will attempt to complete it
625
622
return self ._cmd2_app .basic_complete (text , line , begidx , endidx , self ._subcommand_action .choices )
626
- else :
627
- break
623
+ break
628
624
return []
629
625
630
626
def format_help (self , tokens : list [str ]) -> str :
@@ -642,8 +638,7 @@ def format_help(self, tokens: list[str]) -> str:
642
638
643
639
completer = completer_type (parser , self ._cmd2_app )
644
640
return completer .format_help (tokens [token_index + 1 :])
645
- else :
646
- break
641
+ break
647
642
return self ._parser .format_help ()
648
643
649
644
def _complete_arg (
0 commit comments