in eden/scm/edenscm/mercurial/help.py [0:0]
def helpcmd(self, name, subtopic=None):
ui = self.ui
try:
# Try to expand 'name' as an alias
resolvedargs = cliparser.expandargs(
ui._rcfg._rcfg, list(self.commands.table), name.split(), False
)[0]
if name == "debug":
raise cliparser.AmbiguousCommand()
except cliparser.AmbiguousCommand:
select = lambda c: c.lstrip("^").partition("|")[0].startswith(name)
rst = self.helplist(name, select)
return rst
except cliparser.MalformedAlias as ex:
raise error.Abort(ex.args[0])
if " ".join(resolvedargs) != name:
self.ui.write(_("alias for: %s\n\n") % " ".join(resolvedargs))
# Try to print ":doc" from alias configs
doc = ui.config("alias", "%s:doc" % name)
if doc:
self.ui.write("%s\n\n" % doc)
# Continue with the resolved (non-alias) name
name = " ".join(resolvedargs)
try:
cmd, args, aliases, entry, _level = cmdutil.findsubcmd(
name.split(), self.commands.table, partial=True
)
except error.AmbiguousCommand as inst:
# py3k fix: except vars can't be used outside the scope of the
# except block, nor can be used inside a lambda. python issue4617
prefix = inst.args[0]
select = lambda c: c.lstrip("^").partition("|")[0].startswith(prefix)
rst = self.helplist(name, select)
return rst
except error.UnknownSubcommand as inst:
cmd, subcmd = inst.args[:2]
msg = _("'%s' has no such subcommand: %s") % (cmd, subcmd)
hint = _("run 'hg help %s' to see available subcommands") % cmd
raise error.Abort(msg, hint=hint)
rst = []
# check if it's an invalid alias and display its error if it is
if getattr(entry[0], "badalias", None):
rst.append(entry[0].badalias + "\n")
if entry[0].unknowncmd:
try:
rst.extend(self.helpextcmd(entry[0].cmdname))
except error.UnknownCommand:
pass
return rst
# synopsis
if len(entry) > 2:
if entry[2].startswith("hg"):
rst.append("%s\n" % entry[2])
else:
rst.append("%s %s %s\n" % (identity.prog, cmd, entry[2]))
else:
rst.append("%s %s\n" % (identity.prog, cmd))
# aliases
# try to simplify aliases, ex. compress ['ab', 'abc', 'abcd', 'abcde']
# to ['ab', 'abcde']
slimaliases = []
sortedaliases = sorted(aliases)
for i, alias in enumerate(sortedaliases):
if slimaliases and i + 1 < len(aliases):
nextalias = sortedaliases[i + 1]
if nextalias.startswith(alias) and alias.startswith(slimaliases[-1]):
# Skip this alias
continue
slimaliases.append(alias)
slimaliases = set(slimaliases)
if self.full and not self.ui.quiet and len(slimaliases) > 1:
rst.append(
_("\naliases: %s\n")
% ", ".join(a for a in aliases[1:] if a in slimaliases)
)
rst.append("\n")
# description
doc = gettext(pycompat.getdoc(entry[0]))
if not doc:
doc = _("(no help text available)")
if util.safehasattr(entry[0], "definition"): # aliased command
aliasdoc = ""
if util.safehasattr(entry[0], "aliasdoc") and entry[0].aliasdoc is not None:
lines = entry[0].aliasdoc.splitlines()
if lines:
aliasdoc = (
"\n".join(templater.unquotestring(l) for l in lines) + "\n\n"
)
source = entry[0].source
if entry[0].definition.startswith("!"): # shell alias
doc = _("%sshell alias for::\n\n %s\n\ndefined by: %s\n") % (
aliasdoc,
entry[0].definition[1:],
source,
)
else:
doc = _("%salias for: hg %s\n\n%s\n\ndefined by: %s\n") % (
aliasdoc,
entry[0].definition,
doc,
source,
)
doc = doc.splitlines(True)
if self.ui.quiet or not self.full:
rst.append(doc[0])
else:
rst.extend(doc)
rst.append("\n")
# check if this command shadows a non-trivial (multi-line)
# extension help text
try:
mod = extensions.find(name)
doc = gettext(pycompat.getdoc(mod)) or ""
if "\n" in doc.strip():
msg = _("(use 'hg help -e %s' to show help for the %s extension)") % (
name,
name,
)
rst.append("\n%s\n" % msg)
except KeyError:
pass
# options
if not self.ui.quiet and entry[1]:
rst.append(optrst(_("Options"), entry[1], self.ui.verbose))
if self.ui.verbose:
rst.append(
optrst(_("Global options"), self.commands.globalopts, self.ui.verbose)
)
# subcommands
if util.safehasattr(entry[0], "subcommands") and entry[0].subcommands:
rst.extend(
makesubcmdlist(
cmd,
entry[0].subcommandcategories,
entry[0].subcommands,
self.ui.verbose,
self.ui.quiet,
)
)
if not self.ui.verbose:
if not self.full:
rst.append(_("\n(use 'hg %s -h' to show more help)\n") % name)
elif not self.ui.quiet:
rst.append(
_("\n(some details hidden, use --verbose to show complete help)")
)
return rst