Issue4

Title get command defaults from hgrc
Priority feature Status resolved
Superseder Nosy List mpm, tksoh, tonfa
Assigned To Topics

Created on 2005-10-20.23:32:26 by mpm, last changed 2005-11-01.16:56:16 by mpm.

Messages
msg89 (view) Author: tonfa Date: 2005-10-28.09:54:15
+            try:
+                args = fancyopts.fancyopts(args, globalopts, options)
+            except fancyopts.getopt.GetoptError, inst:
+                raise ParseError(None, inst)

Maybe it should be more specific and warn that it was while adding default options.
msg71 (view) Author: mpm Date: 2005-10-26.23:16:47
Applied
msg65 (view) Author: tksoh Date: 2005-10-26.06:00:12
Here's revised patch. It uses "defaults" now. I also put the defaults before the
command lines'. BTW, do we have options that override others?

# HG changeset patch
# User TK Soh <teekaysoh@yahoo.com>
# Node ID 8a200dbfdaf8c1045933691f0b6df84a90dacad9
# Parent  30146be3437c23b1eff4980767b1f5b48b78e37a
get command defaults from hgrc

diff -r 30146be3437c -r 8a200dbfdaf8 mercurial/commands.py
--- a/mercurial/commands.py	Tue Oct 25 15:54:44 2005 -0700
+++ b/mercurial/commands.py	Wed Oct 26 14:01:37 2005 +0800
@@ -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]))
msg62 (view) Author: mpm Date: 2005-10-26.05:22:59
The section should be called "defaults" with an 's'.

I think the default arguments should be applied before the
user-supplied ones so the later ones can override them.
msg55 (view) Author: tksoh Date: 2005-10-26.03:45:28
not quite optimized, but see if this will work:

# HG changeset patch
# User TK Soh <teekaysoh@yahoo.com>
# Node ID 71c5c4898ad93acfa48714dab902dd92e463047d
# Parent  30146be3437c23b1eff4980767b1f5b48b78e37a
get command defaults from hgrc

diff -r 30146be3437c -r 71c5c4898ad9 mercurial/commands.py
--- a/mercurial/commands.py	Tue Oct 25 15:54:44 2005 -0700
+++ b/mercurial/commands.py	Wed Oct 26 11:47:56 2005 +0800
@@ -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("default", cmd)
+        if defaults:
+            # reparse with command defaults added
+            args = [cmd] + args + defaults.split()
+            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]))
msg3 (view) Author: mpm Date: 2005-10-20.23:32:26
hgrc should have a section:

[defaults]
log=-v
push=-q
History
Date User Action Args
2005-11-01 16:56:16mpmsetstatus: testing -> resolved
nosy: mpm, tonfa, tksoh
2005-10-28 09:54:15tonfasetnosy: + tonfa, tksoh
messages: + msg89
2005-10-26 23:16:47mpmsetmessages: + msg71
2005-10-26 06:00:12tksohsetmessages: + msg65
2005-10-26 05:22:59mpmsetmessages: + msg62
2005-10-26 03:45:28tksohsetstatus: unread -> testing
messages: + msg55
2005-10-20 23:32:26mpmcreate