820 c = list(entry[1]) |
820 c = list(entry[1]) |
821 else: |
821 else: |
822 cmd = None |
822 cmd = None |
823 c = [] |
823 c = [] |
824 |
824 |
|
825 def global_opt_to_fancy_opt(opt_name): |
|
826 # fancyopts() does this transform on `options`, but globalopts uses a |
|
827 # '-', so that it is displayed in the help and accepted as input that |
|
828 # way. |
|
829 return opt_name.replace(b'-', b'_') |
|
830 |
825 # combine global options into local |
831 # combine global options into local |
826 for o in commands.globalopts: |
832 for o in commands.globalopts: |
827 c.append((o[0], o[1], options[o[1]], o[3])) |
833 name = global_opt_to_fancy_opt(o[1]) |
|
834 |
|
835 # The fancyopts name is needed for `options`, but the original name |
|
836 # needs to be used in the second element here, or the parsing for the |
|
837 # command verb fails, saying the command has no such option. |
|
838 c.append((o[0], o[1], options[name], o[3])) |
828 |
839 |
829 try: |
840 try: |
830 args = fancyopts.fancyopts(args, c, cmdoptions, gnu=True) |
841 args = fancyopts.fancyopts(args, c, cmdoptions, gnu=True) |
831 except getopt.GetoptError as inst: |
842 except getopt.GetoptError as inst: |
832 raise error.CommandError(cmd, stringutil.forcebytestr(inst)) |
843 raise error.CommandError(cmd, stringutil.forcebytestr(inst)) |
833 |
844 |
834 # separate global options back out |
845 # separate global options back out |
835 for o in commands.globalopts: |
846 for o in commands.globalopts: |
836 n = o[1] |
847 n = global_opt_to_fancy_opt(o[1]) |
837 options[n] = cmdoptions[n] |
848 options[n] = cmdoptions[n] |
838 del cmdoptions[n] |
849 del cmdoptions[n] |
839 |
850 |
840 return (cmd, cmd and entry[0] or None, args, options, cmdoptions) |
851 return (cmd, cmd and entry[0] or None, args, options, cmdoptions) |
841 |
852 |