@@ -98,6 +98,15 @@ def do_flag(self, args: argparse.Namespace) -> None:
9898 def do_plus_flag (self , args : argparse .Namespace ) -> None :
9999 pass
100100
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+
101110 ############################################################################################################
102111 # Begin code related to testing choices and choices_provider parameters
103112 ############################################################################################################
@@ -519,6 +528,11 @@ def test_subcommand_completions(ac_app, subcommand, text, completions):
519528 ('flag --help --' , '--' , [], []),
520529 ('plus_flag --' , '++' , [], []),
521530 ('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 ' , '' , [], []),
522536 ],
523537)
524538def test_autcomp_flag_completion (ac_app , command_and_args , text , completion_matches , display_matches ):
0 commit comments