comparison mercurial/help.py @ 21289:c3784e3c3e8d

help: suggest keyword search when no topic is found When `hg help foobar` fails, it now suggests using `hg help --keyword foobar` instead of printing a full page of basic commands. This should greatly increases discoverability of the `hg help --keyword` argument.
author Pierre-Yves David <pierre-yves.david@fb.com>
date Wed, 16 Apr 2014 19:55:40 -0400
parents eb6eaef7ae44
children 8225bb1f0ad3
comparison
equal deleted inserted replaced
21288:eb6eaef7ae44 21289:c3784e3c3e8d
484 if not rst: 484 if not rst:
485 msg = _('no matches') 485 msg = _('no matches')
486 hint = _('try "hg help" for a list of topics') 486 hint = _('try "hg help" for a list of topics')
487 raise util.Abort(msg, hint=hint) 487 raise util.Abort(msg, hint=hint)
488 elif name and name != 'shortlist': 488 elif name and name != 'shortlist':
489 i = None
490 if unknowncmd: 489 if unknowncmd:
491 queries = (helpextcmd,) 490 queries = (helpextcmd,)
492 elif opts.get('extension'): 491 elif opts.get('extension'):
493 queries = (helpext,) 492 queries = (helpext,)
494 elif opts.get('command'): 493 elif opts.get('command'):
496 else: 495 else:
497 queries = (helptopic, helpcmd, helpext, helpextcmd) 496 queries = (helptopic, helpcmd, helpext, helpextcmd)
498 for f in queries: 497 for f in queries:
499 try: 498 try:
500 rst = f(name) 499 rst = f(name)
501 i = None
502 break 500 break
503 except error.UnknownCommand, inst: 501 except error.UnknownCommand:
504 i = inst 502 pass
505 if i: 503 else:
506 raise i 504 if unknowncmd:
505 raise error.UnknownCommand(name)
506 else:
507 msg = _('no such help topic: %s') % name
508 hint = _('try "hg help --keyword %s"') % name
509 raise util.Abort(msg, hint=hint)
507 else: 510 else:
508 # program name 511 # program name
509 if not ui.quiet: 512 if not ui.quiet:
510 rst = [_("Mercurial Distributed SCM\n"), '\n'] 513 rst = [_("Mercurial Distributed SCM\n"), '\n']
511 rst.extend(helplist()) 514 rst.extend(helplist())