Mercurial > public > mercurial-scm > python-hglib
diff hglib/util.py @ 205:2d0ec6097d78 2.6.1
util: fix handling of empty short option
This one was overlooked at 32e8d51ec16c. A dense form, '-sVALUE', shouldn't
be used if an empty value is specified.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Mon, 30 Apr 2018 15:43:29 +0900 |
parents | 32e8d51ec16c |
children |
line wrap: on
line diff
--- a/hglib/util.py Wed Apr 25 13:32:18 2018 -0400 +++ b/hglib/util.py Mon Apr 30 15:43:29 2018 +0900 @@ -111,6 +111,14 @@ True >>> cmdbuilder(b('cmd'), b('-a')) == [b('cmd'), b('--'), b('-a')] True + >>> cmdbuilder(b('cmd'), b('')) == [b('cmd'), b('--'), b('')] + True + >>> cmdbuilder(b('cmd'), s=b('')) == [b('cmd'), b('-s'), b('')] + True + >>> cmdbuilder(b('cmd'), s=[b('')]) == [b('cmd'), b('-s'), b('')] + True + >>> cmdbuilder(b('cmd'), long=b('')) == [b('cmd'), b('--long=')] + True """ cmd = [name] for arg, val in kwargs.items(): @@ -118,8 +126,9 @@ continue arg = pfx = arg.encode('latin-1').replace(b('_'), b('-')) + short = (len(arg) == 1) if arg != b('-'): - if len(arg) == 1: + if short: arg = pfx = b('-') + arg else: arg = b('--') + arg @@ -129,9 +138,17 @@ cmd.append(arg) elif isinstance(val, list): for v in val: - cmd.append(pfx + _cmdval(v)) + s = _cmdval(v) + if s or not short: + cmd.append(pfx + s) + else: + cmd.extend([arg, s]) else: - cmd.append(pfx + _cmdval(val)) + s = _cmdval(val) + if s or not short: + cmd.append(pfx + s) + else: + cmd.extend([arg, s]) args = [a for a in args if a is not None] if args: