@@ -98,6 +98,15 @@ def do_flag(self, args: argparse.Namespace) -> None:
98
98
def do_plus_flag (self , args : argparse .Namespace ) -> None :
99
99
pass
100
100
101
+ # A parser with a positional and flags. Used to test that remaining flag names are completed when all positionals are done.
102
+ pos_and_flag_parser = Cmd2ArgumentParser ()
103
+ pos_and_flag_parser .add_argument ("positional" , choices = ["a" , "choice" ])
104
+ pos_and_flag_parser .add_argument ("-f" , "--flag" , action = 'store_true' )
105
+
106
+ @with_argparser (pos_and_flag_parser )
107
+ def do_pos_and_flag (self , args : argparse .Namespace ) -> None :
108
+ pass
109
+
101
110
############################################################################################################
102
111
# Begin code related to testing choices and choices_provider parameters
103
112
############################################################################################################
@@ -519,6 +528,11 @@ def test_subcommand_completions(ac_app, subcommand, text, completions):
519
528
('flag --help --' , '--' , [], []),
520
529
('plus_flag --' , '++' , [], []),
521
530
('plus_flag ++help --' , '++' , [], []),
531
+ # Test remaining flag names complete after all positionals are complete
532
+ ('pos_and_flag' , '' , ['a' , 'choice' ], ['a' , 'choice' ]),
533
+ ('pos_and_flag choice ' , '' , ['--flag' , '--help' , '-f' , '-h' ], ['[-f, --flag]' , '[-h, --help]' ]),
534
+ ('pos_and_flag choice -f ' , '' , ['--help' , '-h' ], ['[-h, --help]' ]),
535
+ ('pos_and_flag choice -f -h ' , '' , [], []),
522
536
],
523
537
)
524
538
def test_autcomp_flag_completion (ac_app , command_and_args , text , completion_matches , display_matches ):
0 commit comments