mercurial/debugcommands.py
changeset 30505 158b41842fd2
parent 30504 c3bdc27121d1
child 30514 625ccc95fa96
--- a/mercurial/debugcommands.py	Wed Aug 17 20:40:13 2016 -0700
+++ b/mercurial/debugcommands.py	Wed Aug 17 20:41:05 2016 -0700
@@ -329,3 +329,31 @@
         cmd = cmd.split('|')[0].strip('^')
         opts = ', '.join([i[1] for i in vals[1]])
         ui.write('%s: %s\n' % (cmd, opts))
+
+@command('debugcomplete',
+    [('o', 'options', None, _('show the command options'))],
+    _('[-o] CMD'),
+    norepo=True)
+def debugcomplete(ui, cmd='', **opts):
+    """returns the completion list associated with the given command"""
+
+    if opts.get('options'):
+        options = []
+        otables = [commands.globalopts]
+        if cmd:
+            aliases, entry = cmdutil.findcmd(cmd, commands.table, False)
+            otables.append(entry[1])
+        for t in otables:
+            for o in t:
+                if "(DEPRECATED)" in o[3]:
+                    continue
+                if o[0]:
+                    options.append('-%s' % o[0])
+                options.append('--%s' % o[1])
+        ui.write("%s\n" % "\n".join(options))
+        return
+
+    cmdlist, unused_allcmds = cmdutil.findpossible(cmd, commands.table)
+    if ui.verbose:
+        cmdlist = [' '.join(c[0]) for c in cmdlist.values()]
+    ui.write("%s\n" % "\n".join(sorted(cmdlist)))