get command defaults from hgrc
authorTK Soh <teekaysoh@yahoo.com>
Wed, 26 Oct 2005 16:10:36 -0700
changeset 1453 6fbb13b7a59f
parent 1452 f1755621cb7d
child 1454 f4250806dbeb
get command defaults from hgrc
mercurial/commands.py
--- a/mercurial/commands.py	Tue Oct 25 22:17:31 2005 -0700
+++ b/mercurial/commands.py	Wed Oct 26 16:10:36 2005 -0700
@@ -2417,7 +2417,7 @@
 class ParseError(Exception):
     """Exception raised on errors in parsing the command line."""
 
-def parse(args):
+def parse(ui, args):
     options = {}
     cmdoptions = {}
 
@@ -2428,6 +2428,17 @@
 
     if args:
         cmd, args = args[0], args[1:]
+        defaults = ui.config("defaults", cmd)
+        if defaults:
+            # reparse with command defaults added
+            args = [cmd] + defaults.split() + args
+            try:
+                args = fancyopts.fancyopts(args, globalopts, options)
+            except fancyopts.getopt.GetoptError, inst:
+                raise ParseError(None, inst)
+
+            cmd, args = args[0], args[1:]
+
         i = find(cmd)[1]
         c = list(i[1])
     else:
@@ -2494,7 +2505,7 @@
         table.update(cmdtable)
 
     try:
-        cmd, func, args, options, cmdoptions = parse(args)
+        cmd, func, args, options, cmdoptions = parse(u, args)
     except ParseError, inst:
         if inst.args[0]:
             u.warn(_("hg %s: %s\n") % (inst.args[0], inst.args[1]))