##// END OF EJS Templates
githelp: make argument parsing more compatible with Python 3...
Gregory Szorc -
r41459:031d9162 default
parent child Browse files
Show More
@@ -25,6 +25,7 b' from mercurial import ('
25 encoding,
25 encoding,
26 error,
26 error,
27 fancyopts,
27 fancyopts,
28 pycompat,
28 registrar,
29 registrar,
29 scmutil,
30 scmutil,
30 )
31 )
@@ -83,20 +84,22 b' def parseoptions(ui, cmdoptions, args):'
83 args = fancyopts.fancyopts(list(args), cmdoptions, opts, True)
84 args = fancyopts.fancyopts(list(args), cmdoptions, opts, True)
84 break
85 break
85 except getopt.GetoptError as ex:
86 except getopt.GetoptError as ex:
86 if "requires argument" in ex.msg:
87 if r"requires argument" in ex.msg:
87 raise
88 raise
88 if ('--' + ex.opt) in ex.msg:
89 if (r'--' + ex.opt) in ex.msg:
89 flag = '--' + ex.opt
90 flag = '--' + pycompat.bytestr(ex.opt)
90 elif ('-' + ex.opt) in ex.msg:
91 elif (r'-' + ex.opt) in ex.msg:
91 flag = '-' + ex.opt
92 flag = '-' + pycompat.bytestr(ex.opt)
92 else:
93 else:
93 raise error.Abort(_("unknown option %s") % ex.opt)
94 raise error.Abort(_("unknown option %s") %
95 pycompat.bytestr(ex.opt))
94 try:
96 try:
95 args.remove(flag)
97 args.remove(flag)
96 except Exception:
98 except Exception:
97 msg = _("unknown option '%s' packed with other options")
99 msg = _("unknown option '%s' packed with other options")
98 hint = _("please try passing the option as its own flag: -%s")
100 hint = _("please try passing the option as its own flag: -%s")
99 raise error.Abort(msg % ex.opt, hint=hint % ex.opt)
101 raise error.Abort(msg % pycompat.bytestr(ex.opt),
102 hint=hint % pycompat.bytestr(ex.opt))
100
103
101 ui.warn(_("ignoring unknown option %s\n") % flag)
104 ui.warn(_("ignoring unknown option %s\n") % flag)
102
105
General Comments 0
You need to be logged in to leave comments. Login now