githelp: make argument parsing more compatible with Python 3
There were various mixing of str and bytes in here. This change
fixes most of the failures in test-githelp.t.
Differential Revision: https://phab.mercurial-scm.org/D5725
--- a/hgext/githelp.py Sat Jan 26 14:08:35 2019 -0800
+++ b/hgext/githelp.py Sat Jan 26 14:14:44 2019 -0800
@@ -25,6 +25,7 @@
encoding,
error,
fancyopts,
+ pycompat,
registrar,
scmutil,
)
@@ -83,20 +84,22 @@
args = fancyopts.fancyopts(list(args), cmdoptions, opts, True)
break
except getopt.GetoptError as ex:
- if "requires argument" in ex.msg:
+ if r"requires argument" in ex.msg:
raise
- if ('--' + ex.opt) in ex.msg:
- flag = '--' + ex.opt
- elif ('-' + ex.opt) in ex.msg:
- flag = '-' + ex.opt
+ if (r'--' + ex.opt) in ex.msg:
+ flag = '--' + pycompat.bytestr(ex.opt)
+ elif (r'-' + ex.opt) in ex.msg:
+ flag = '-' + pycompat.bytestr(ex.opt)
else:
- raise error.Abort(_("unknown option %s") % ex.opt)
+ raise error.Abort(_("unknown option %s") %
+ pycompat.bytestr(ex.opt))
try:
args.remove(flag)
except Exception:
msg = _("unknown option '%s' packed with other options")
hint = _("please try passing the option as its own flag: -%s")
- raise error.Abort(msg % ex.opt, hint=hint % ex.opt)
+ raise error.Abort(msg % pycompat.bytestr(ex.opt),
+ hint=hint % pycompat.bytestr(ex.opt))
ui.warn(_("ignoring unknown option %s\n") % flag)