Mercurial > public > mercurial-scm > hg-stable
diff mercurial/dispatch.py @ 52757:1ccbca64610a
dispatch: allow global options with a '-' in the long name
The handful of current global commands are one word, so this hasn't been
necessary. Unfortunately, the `fancyopts` class transforms `--long-arg-name`
into `long_arg_name` when it populates the `options` list used here. That
results in a KeyError when iterating over `commands.globalopts` and doing a
lookup with the dash-based name that is required there, in order to have the
dash-based name in the user interface.
author | Matt Harbison <matt_harbison@yahoo.com> |
---|---|
date | Wed, 29 Jan 2025 16:04:39 -0500 |
parents | 73ab542565e0 |
children | 25b344f2aeef |
line wrap: on
line diff
--- a/mercurial/dispatch.py Thu Feb 06 23:04:55 2025 +0100 +++ b/mercurial/dispatch.py Wed Jan 29 16:04:39 2025 -0500 @@ -822,9 +822,20 @@ cmd = None c = [] + def global_opt_to_fancy_opt(opt_name): + # fancyopts() does this transform on `options`, but globalopts uses a + # '-', so that it is displayed in the help and accepted as input that + # way. + return opt_name.replace(b'-', b'_') + # combine global options into local for o in commands.globalopts: - c.append((o[0], o[1], options[o[1]], o[3])) + name = global_opt_to_fancy_opt(o[1]) + + # The fancyopts name is needed for `options`, but the original name + # needs to be used in the second element here, or the parsing for the + # command verb fails, saying the command has no such option. + c.append((o[0], o[1], options[name], o[3])) try: args = fancyopts.fancyopts(args, c, cmdoptions, gnu=True) @@ -833,7 +844,7 @@ # separate global options back out for o in commands.globalopts: - n = o[1] + n = global_opt_to_fancy_opt(o[1]) options[n] = cmdoptions[n] del cmdoptions[n]