add --options to debugcomplete and change bash_completion to use it
authorAlexis S. L. Carvalho <alexis@cecm.usp.br>
Sat, 01 Apr 2006 22:50:12 +0200
changeset 2034 5e7aff1b6ae1
parent 2033 e3280d350792
child 2035 107dc72880f8
add --options to debugcomplete and change bash_completion to use it make debugcomplete print one item per line (this is not needed for the bash_completion script, but should be easier to use in other scripts)
contrib/bash_completion
mercurial/commands.py
--- a/contrib/bash_completion	Sat Apr 01 21:37:08 2006 +0200
+++ b/contrib/bash_completion	Sat Apr 01 22:50:12 2006 +0200
@@ -1,18 +1,5 @@
 shopt -s extglob
 
-_hg_option_list()
-{
-    "$hg" -v help $1 2>/dev/null | \
-	awk '/^ *-/ {
-		for (i = 1; i <= NF; i ++) {
-		    if (index($i, "-") != 1)
-			break;
-		    print $i;
-		}
-	    }'
-}
-
-
 _hg_commands()
 {
     local commands
@@ -89,7 +76,7 @@
     done
 
     if [[ "$cur" == -* ]]; then
-	opts=$(_hg_option_list $cmd)
+	opts=$("$hg" debugcomplete --options "$cmd" 2>/dev/null)
 
 	COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$opts' -- "$cur"))
 	return
--- a/mercurial/commands.py	Sat Apr 01 21:37:08 2006 +0200
+++ b/mercurial/commands.py	Sat Apr 01 22:50:12 2006 +0200
@@ -1272,11 +1272,26 @@
     a = r.ancestor(r.lookup(rev1), r.lookup(rev2))
     ui.write("%d:%s\n" % (r.rev(a), hex(a)))
 
-def debugcomplete(ui, cmd):
+def debugcomplete(ui, cmd='', **opts):
     """returns the completion list associated with the given command"""
+
+    if opts['options']:
+        options = []
+        otables = [globalopts]
+        if cmd:
+            aliases, entry = find(cmd)
+            otables.append(entry[1])
+        for t in otables:
+            for o in t:
+                if o[0]:
+                    options.append('-%s' % o[0])
+                options.append('--%s' % o[1])
+        ui.write("%s\n" % "\n".join(options))
+        return
+
     clist = findpossible(cmd).keys()
     clist.sort()
-    ui.write("%s\n" % " ".join(clist))
+    ui.write("%s\n" % "\n".join(clist))
 
 def debugrebuildstate(ui, repo, rev=None):
     """rebuild the dirstate as it would look like for the given revision"""
@@ -2853,7 +2868,10 @@
           ('X', 'exclude', [], _('exclude names matching the given patterns'))],
          _('hg copy [OPTION]... [SOURCE]... DEST')),
     "debugancestor": (debugancestor, [], _('debugancestor INDEX REV1 REV2')),
-    "debugcomplete": (debugcomplete, [], _('debugcomplete CMD')),
+    "debugcomplete":
+        (debugcomplete,
+         [('o', 'options', None, _('show the command options'))],
+         _('debugcomplete [-o] CMD')),
     "debugrebuildstate":
         (debugrebuildstate,
          [('r', 'rev', '', _('revision to rebuild to'))],