gh-126390: Support for preserving order of options and nonoption arguments in gnu_getopt() (GH-126393)

This commit is contained in:
Serhiy Storchaka 2024-11-13 22:50:46 +02:00 committed by GitHub
parent 12ca7e622f
commit 35010b8cf2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 48 additions and 5 deletions

View file

@ -173,6 +173,12 @@ class GetoptTests(unittest.TestCase):
self.assertEqual(args, ['-'])
self.assertEqual(opts, [('-a', ''), ('-b', '-')])
# Return positional arguments intermixed with options.
opts, args = getopt.gnu_getopt(cmdline, '-ab:', ['alpha', 'beta='])
self.assertEqual(args, ['arg2'])
self.assertEqual(opts, [('-a', ''), (None, ['arg1']), ('-b', '1'), ('--alpha', ''),
('--beta', '2'), ('--beta', '3')])
# Posix style via +
opts, args = getopt.gnu_getopt(cmdline, '+ab:', ['alpha', 'beta='])
self.assertEqual(opts, [('-a', '')])