diff options
author | steven.bethard <devnull@localhost> | 2009-12-07 00:56:45 +0000 |
---|---|---|
committer | steven.bethard <devnull@localhost> | 2009-12-07 00:56:45 +0000 |
commit | 595bce353fc65c44168df31a9cd3e29b9059b486 (patch) | |
tree | 00044595d631f68c64a1ce75fa68aa0c7ac1e36f | |
parent | d8a9e95d1809e508aa8720b26e98510ef414aa0e (diff) | |
download | argparse-595bce353fc65c44168df31a9cd3e29b9059b486.tar.gz |
Fix bug where --si=64 was deemed ambiguous when both --si and --size were in the parser.
-rw-r--r-- | argparse.py | 7 | ||||
-rw-r--r-- | test/test_argparse.py | 19 |
2 files changed, 26 insertions, 0 deletions
diff --git a/argparse.py b/argparse.py index 16a778f..8b96e62 100644 --- a/argparse.py +++ b/argparse.py @@ -2036,6 +2036,13 @@ class ArgumentParser(_AttributeHolder, _ActionsContainer): action = self._option_string_actions[arg_string] return action, arg_string, None + # if the option string before the "=" is present, return the action + if '=' in arg_string: + option_string, explicit_arg = arg_string.split('=', 1) + if option_string in self._option_string_actions: + action = self._option_string_actions[option_string] + return action, option_string, explicit_arg + # search through all possible prefixes of the option string # and all actions in the parser for possible interpretations option_tuples = self._get_option_tuples(arg_string) diff --git a/test/test_argparse.py b/test/test_argparse.py index 2356389..a7eb74a 100644 --- a/test/test_argparse.py +++ b/test/test_argparse.py @@ -401,6 +401,25 @@ class TestOptionalsDoubleDashPartialMatch(ParserTestCase): ] +class TestOptionalsDoubleDashPrefixMatch(ParserTestCase): + """Tests when one double-dash option string is a prefix of another""" + + argument_signatures = [ + Sig('--badger', action='store_true'), + Sig('--ba'), + ] + failures = ['--bar', '--b', '--ba', '--b=2', '--badge 5'] + successes = [ + ('', NS(badger=False, ba=None)), + ('--ba X', NS(badger=False, ba='X')), + ('--ba=X', NS(badger=False, ba='X')), + ('--bad', NS(badger=True, ba=None)), + ('--badg', NS(badger=True, ba=None)), + ('--badge', NS(badger=True, ba=None)), + ('--badger', NS(badger=True, ba=None)), + ] + + class TestOptionalsSingleDoubleDash(ParserTestCase): """Test an Optional with single- and double-dash option strings""" |