[PATCH]: shell-complete command

Clint Adams schizo at debian.org
Tue Aug 23 01:15:56 BST 2005


> The output of shell-complete probably should be modified to
> facilitate this.  For example, in the output of
> "shell-complete branch", there is no indication that -r takes an
> argument.  It would be preferable if this information were available
> for shell-complete to spew forth.

This is one way to address that problem.

*** modified file 'bzrlib/commands.py'
--- bzrlib/commands.py 
+++ bzrlib/commands.py 
@@ -221,7 +221,7 @@
     aliases = []
     
     takes_args = []
-    takes_options = []
+    takes_options = {}
 
     hidden = False
     
@@ -289,7 +289,7 @@
         pipe = os.popen('%s --bzr-usage' % path, 'r')
         self.takes_options = pipe.readline().split()
 
-        for opt in self.takes_options:
+        for opt in self.takes_options.keys():
             if not opt in OPTIONS:
                 raise BzrError("Unknown option '%s' returned by external command %s"
                                % (opt, path))
@@ -374,7 +374,7 @@
     If a revision is specified, the changes since that revision are shown.
     """
     takes_args = ['file*']
-    takes_options = ['all', 'show-ids', 'revision']
+    takes_options = {'all':None, 'show-ids':None, 'revision':'rev'}
     aliases = ['st', 'stat']
     
     def run(self, all=False, show_ids=False, file_list=None):
@@ -416,7 +416,7 @@
     """
     hidden = True
     takes_args = ['revision_info*']
-    takes_options = ['revision']
+    takes_options = {'revision':'rev'}
     def run(self, revision=None, revision_info_list=None):
         from bzrlib.branch import find_branch
 
@@ -456,7 +456,7 @@
     recursively add that parent, rather than giving an error?
     """
     takes_args = ['file*']
-    takes_options = ['verbose', 'no-recurse']
+    takes_options = {'verbose':None, 'no-recurse':None}
     
     def run(self, file_list, verbose=False, no_recurse=False):
         from bzrlib.add import smart_add
@@ -493,7 +493,7 @@
 
 class cmd_inventory(Command):
     """Show inventory of the current working copy or a revision."""
-    takes_options = ['revision', 'show-ids']
+    takes_options = {'revision':'rev', 'show-ids':None}
     
     def run(self, revision=None, show_ids=False):
         b = find_branch('.')
@@ -652,7 +652,7 @@
     parameter, as in "branch foo/bar -r 5".
     """
     takes_args = ['from_location', 'to_location?']
-    takes_options = ['revision']
+    takes_options = {'revision':'rev'}
     aliases = ['get', 'clone']
 
     def run(self, from_location, to_location=None, revision=None):
@@ -767,7 +767,7 @@
     not delete the working copy.
     """
     takes_args = ['file+']
-    takes_options = ['verbose']
+    takes_options = {'verbose':None}
     
     def run(self, file_list, verbose=False):
         b = find_branch(file_list[0])
@@ -873,7 +873,7 @@
     """
     
     takes_args = ['file*']
-    takes_options = ['revision', 'diff-options']
+    takes_options = {'revision':'rev', 'diff-options':'diffopts'}
     aliases = ['di', 'dif']
 
     def run(self, revision=None, file_list=None, diff_options=None):
@@ -987,8 +987,9 @@
     """
 
     takes_args = ['filename?']
-    takes_options = ['forward', 'timezone', 'verbose', 'show-ids', 'revision',
-                     'long', 'message', 'short',]
+    takes_options = {'forward':None, 'timezone':None, 'verbose':None, 'show-ids':None,
+		     'revision':'revrange', 'long':None, 'message':'regex',
+		     'short':None}
     
     def run(self, filename=None, timezone='original',
             verbose=False,
@@ -1211,7 +1212,7 @@
     is given, the top directory will be the root name of the file."""
     # TODO: list known exporters
     takes_args = ['dest']
-    takes_options = ['revision', 'format', 'root']
+    takes_options = {'revision':'rev', 'format':'exportername', 'root':'dir'}
     def run(self, dest, revision=None, format=None, root=None):
         import os.path
         b = find_branch('.')
@@ -1238,7 +1239,7 @@
 class cmd_cat(Command):
     """Write a file's text from a previous revision."""
 
-    takes_options = ['revision']
+    takes_options = {'revision':'rev'}
     takes_args = ['filename']
 
     def run(self, filename, revision=None):
@@ -1276,7 +1277,8 @@
     TODO: Strict commit that fails if there are unknown or deleted files.
     """
     takes_args = ['selected*']
-    takes_options = ['message', 'file', 'verbose', 'unchanged']
+    takes_options = {'message':None, 'file':None, 'verbose':None,
+                     'unchanged':None}
     aliases = ['ci', 'checkin']
 
     # TODO: Give better message for -s, --summary, used by tla people
@@ -1378,7 +1380,7 @@
 
 class cmd_whoami(Command):
     """Show bzr user id."""
-    takes_options = ['email']
+    takes_options = {'email':None}
     
     def run(self, email=False):
         try:
@@ -1395,7 +1397,7 @@
 class cmd_selftest(Command):
     """Run internal test suite"""
     hidden = True
-    takes_options = ['verbose']
+    takes_options = {'verbose':None}
     def run(self, verbose=False):
         from bzrlib.selftest import selftest
         return int(not selftest(verbose=verbose))
@@ -1483,7 +1485,7 @@
     --force is given.
     """
     takes_args = ['branch?']
-    takes_options = ['revision', 'force', 'merge-type']
+    takes_options = {'revision':'revpair', 'force':None, 'merge-type':None}
 
     def run(self, branch='.', revision=None, force=False, 
             merge_type=None):
@@ -1517,7 +1519,7 @@
     those files.  By default, any files that are changed will be backed up
     first.  Backup files have a '~' appended to their name.
     """
-    takes_options = ['revision', 'no-backup']
+    takes_options = {'revision':'rev', 'no-backup':None}
     takes_args = ['file*']
     aliases = ['merge-revert']
 
@@ -1576,7 +1578,7 @@
     aliases = ['mis', 'miss']
     # We don't have to add quiet to the list, because 
     # unknown options are parsed as booleans
-    takes_options = ['verbose', 'quiet']
+    takes_options = {'verbose':None, 'quiet':None}
 
     def run(self, remote=None, verbose=False, quiet=False):
         from bzrlib.branch import find_branch, DivergedBranches
@@ -1875,7 +1877,7 @@
                    get_cmd_class(cmd, plugins_override=not opt_builtin)
 
     # check options are reasonable
-    allowed = cmd_class.takes_options
+    allowed = cmd_class.takes_options.keys()
     for oname in opts:
         if oname not in allowed:
             raise BzrCommandError("option '--%s' is not allowed for command %r"

*** modified file 'bzrlib/shellcomplete.py'
--- bzrlib/shellcomplete.py 
+++ bzrlib/shellcomplete.py 
@@ -37,13 +37,26 @@
     if outfile == None:
         outfile = sys.stdout
 
-    for on in options:
+    for on in options.keys():
         for shortname, longname in commands.SHORT_OPTIONS.items():
             if longname == on:
                 l = '"(--' + on + ' -' + shortname + ')"{--' + on + ',-' + shortname + '}'
-                break
 	    else:
 		l = '--' + on
+
+	    if options[on] == 'rev':
+		l += ':revision:'
+	    elif options[on] == 'revpair':
+		l += ':revision pair:'
+	    elif options[on] == 'revrange':
+		l += ':revision range:'
+	    elif options[on] == 'diffopts':
+		l += ':diff options:'
+	    elif options[on] == 'exportername':
+		l += ':exporter name:"(tar tgz tbz2)"'
+	    elif options[on] == 'dir':
+		l += ':dir:"_files -/"'
+
         outfile.write(l + '\n')
 
 





More information about the bazaar mailing list