[Pkg-bazaar-commits] ./bzr/unstable r272: - Add command aliases

Martin Pool mbp at sourcefrog.net
Fri Apr 10 07:51:36 UTC 2009


------------------------------------------------------------
revno: 272
committer: Martin Pool <mbp at sourcefrog.net>
timestamp: Fri 2005-04-15 18:26:52 +1000
message:
  - Add command aliases
modified:
  NEWS
  bzrlib/commands.py
  test.sh
-------------- next part --------------
=== modified file 'NEWS'
--- a/NEWS	2005-04-15 02:50:53 +0000
+++ b/NEWS	2005-04-15 08:26:52 +0000
@@ -12,6 +12,9 @@
 
     * Roll over ~/.bzr.log if it gets too large.
 
+    * Command abbreviations 'ci', 'st', 'stat', '?' based on a patch
+      by Jason Diamon.
+
 
   CHANGES:
 

=== modified file 'bzrlib/commands.py'
--- a/bzrlib/commands.py	2005-04-15 07:53:59 +0000
+++ b/bzrlib/commands.py	2005-04-15 08:26:52 +0000
@@ -116,6 +116,29 @@
 
 
 
+cmd_aliases = {
+    '?':         'help',
+    'ci':        'commit',
+    'checkin':   'commit',
+    'di':        'diff',
+    'st':        'status',
+    'stat':      'status',
+    }
+
+
+def get_cmd_handler(cmd):
+    assert isinstance(cmd, str)
+    
+    cmd = cmd_aliases.get(cmd, cmd)
+    
+    try:
+        cmd_handler = globals()['cmd_' + cmd.replace('-', '_')]
+    except KeyError:
+        raise BzrError("unknown command %r" % cmd)
+
+    return cmd, cmd_handler
+
+
 
 def cmd_status(all=False):
     """Display status summary.
@@ -711,10 +734,7 @@
         return
 
     # otherwise, maybe the name of a command?
-    try:
-        cmdfn = globals()['cmd_' + topic.replace('-', '_')]
-    except KeyError:
-        bailout("no help for %r" % topic)
+    topic, cmdfn = get_cmd_handler(topic)
 
     doc = getdoc(cmdfn)
     if doc == None:
@@ -962,10 +982,7 @@
         log_error('  try "bzr help"')
         return 1
 
-    try:
-        cmd_handler = globals()['cmd_' + cmd.replace('-', '_')]
-    except KeyError:
-        bailout("unknown command " + `cmd`)
+    canonical_cmd, cmd_handler = get_cmd_handler(cmd)
 
     # global option
     if 'profile' in opts:
@@ -975,7 +992,7 @@
         profile = False
 
     # check options are reasonable
-    allowed = cmd_options.get(cmd, [])
+    allowed = cmd_options.get(canonical_cmd, [])
     for oname in opts:
         if oname not in allowed:
             bailout("option %r is not allowed for command %r"
@@ -986,7 +1003,7 @@
     # options" (it is an oxymoron)
 
     # mix arguments and options into one dictionary
-    cmdargs = _match_args(cmd, args)
+    cmdargs = _match_args(canonical_cmd, args)
     for k, v in opts.items():
         cmdargs[k.replace('-', '_')] = v
 

=== modified file 'test.sh'
--- a/test.sh	2005-04-15 01:08:24 +0000
+++ b/test.sh	2005-04-15 08:26:52 +0000
@@ -60,6 +60,9 @@
 ?       test.txt
 EOF
 
+# command alias
+bzr st --all | diff -u - status.tmp
+
 # can't rename unversioned files; use the regular unix rename command
 ! bzr rename test.txt new-test.txt
 



More information about the Pkg-bazaar-commits mailing list