Skip to content
This repository was archived by the owner on Mar 29, 2024. It is now read-only.

Commit 4b6223c

Browse files
committed
Merge pull request #131 from twobraids/fix_command_line
make get_opt truly ignore unknown options
2 parents 3e3c72a + 3b6bf2e commit 4b6223c

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

configman/tests/test_val_for_getopt.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,11 @@ def test_for_getopt_with_ignore(self):
118118
args = ['-a', '14', '--fred', 'sally', 'ethel', 'dwight']
119119
o, a = function(args, '', [])
120120
self.assertEqual([], o)
121-
self.assertEqual(a, args)
121+
self.assertEqual(a, ['14', 'sally', 'ethel', 'dwight'])
122122
args = ['-a', '14', '--fred', 'sally', 'ethel', 'dwight']
123123
o, a = function(args, 'a:', [])
124124
self.assertEqual(o, [('-a', '14')])
125-
self.assertEqual(a, ['--fred', 'sally', 'ethel', 'dwight'])
125+
self.assertEqual(a, ['sally', 'ethel', 'dwight'])
126126
args = ['-a', '14', '--fred', 'sally', 'ethel', 'dwight']
127127
o, a = function(args, 'a', ['fred='])
128128
self.assertEqual(o, [('-a', ''), ('--fred', 'sally')])

configman/value_sources/for_getopt.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -217,19 +217,25 @@ def getopt_with_ignore(args, shortopts, longopts=[]):
217217
if args[0] == '--':
218218
prog_args += args[1:]
219219
break
220-
if args[0][:2] == '--':
220+
if args[0].startswith('--'):
221221
try:
222-
opts, args = getopt.do_longs(opts, args[0][2:],
223-
longopts, args[1:])
222+
opts, args = getopt.do_longs(
223+
opts,
224+
args[0][2:],
225+
longopts,
226+
args[1:]
227+
)
224228
except getopt.GetoptError:
225-
prog_args.append(args[0])
226229
args = args[1:]
227-
elif args[0][:1] == '-':
230+
elif args[0][0] == '-':
228231
try:
229-
opts, args = getopt.do_shorts(opts, args[0][1:], shortopts,
230-
args[1:])
232+
opts, args = getopt.do_shorts(
233+
opts,
234+
args[0][1:],
235+
shortopts,
236+
args[1:]
237+
)
231238
except getopt.GetoptError:
232-
prog_args.append(args[0])
233239
args = args[1:]
234240
else:
235241
prog_args.append(args[0])

0 commit comments

Comments
 (0)