Mercurial > hg
comparison mercurial/dispatch.py @ 31060:ab20491b1760
dispatch: rearrange 'unknown command' code to better employ pager
dispatch calls help like a ninja if you give it a truly unknown
command, and that might want to be paged. If it gets paged, then the
'hg: unknown command' text gets eaten by a grue, unless we call the
pager first. This change rearranges the codepaths so we can safely
only invoke the pager in the case where we'll have long output from
the help command code, rather than just a short message like "did you
mean stat instead of start" or "fetch is provided by the fetch
extension".
author | Augie Fackler <augie@google.com> |
---|---|
date | Tue, 21 Feb 2017 14:20:05 -0500 |
parents | 04344226b3ce |
children | 45be7590301d |
comparison
equal
deleted
inserted
replaced
31059:2a0c8e3636b0 | 31060:ab20491b1760 |
---|---|
31 encoding, | 31 encoding, |
32 error, | 32 error, |
33 extensions, | 33 extensions, |
34 fancyopts, | 34 fancyopts, |
35 fileset, | 35 fileset, |
36 help, | |
36 hg, | 37 hg, |
37 hook, | 38 hook, |
38 profiling, | 39 profiling, |
39 pycompat, | 40 pycompat, |
40 revset, | 41 revset, |
240 commands.help_(ui, 'shortlist') | 241 commands.help_(ui, 'shortlist') |
241 except error.ParseError as inst: | 242 except error.ParseError as inst: |
242 _formatparse(ui.warn, inst) | 243 _formatparse(ui.warn, inst) |
243 return -1 | 244 return -1 |
244 except error.UnknownCommand as inst: | 245 except error.UnknownCommand as inst: |
245 ui.warn(_("hg: unknown command '%s'\n") % inst.args[0]) | 246 nocmdmsg = _("hg: unknown command '%s'\n") % inst.args[0] |
246 try: | 247 try: |
247 # check if the command is in a disabled extension | 248 # check if the command is in a disabled extension |
248 # (but don't check for extensions themselves) | 249 # (but don't check for extensions themselves) |
249 commands.help_(ui, inst.args[0], unknowncmd=True) | 250 formatted = help.formattedhelp(ui, inst.args[0], unknowncmd=True) |
251 ui.warn(nocmdmsg) | |
252 ui.write(formatted) | |
250 except (error.UnknownCommand, error.Abort): | 253 except (error.UnknownCommand, error.Abort): |
251 suggested = False | 254 suggested = False |
252 if len(inst.args) == 2: | 255 if len(inst.args) == 2: |
253 sim = _getsimilar(inst.args[1], inst.args[0]) | 256 sim = _getsimilar(inst.args[1], inst.args[0]) |
254 if sim: | 257 if sim: |
258 ui.warn(nocmdmsg) | |
255 _reportsimilar(ui.warn, sim) | 259 _reportsimilar(ui.warn, sim) |
256 suggested = True | 260 suggested = True |
257 if not suggested: | 261 if not suggested: |
262 ui.pager('help') | |
263 ui.warn(nocmdmsg) | |
258 commands.help_(ui, 'shortlist') | 264 commands.help_(ui, 'shortlist') |
259 except IOError: | 265 except IOError: |
260 raise | 266 raise |
261 except KeyboardInterrupt: | 267 except KeyboardInterrupt: |
262 raise | 268 raise |