##// END OF EJS Templates
move the parsing of --config options to commands.py
Alexis S. L. Carvalho -
r3346:1700a103 default
parent child Browse files
Show More
@@ -3275,6 +3275,20 b' def load_extensions(ui):'
3275 ui.warn(_("module %s overrides %s\n") % (name, t))
3275 ui.warn(_("module %s overrides %s\n") % (name, t))
3276 table.update(cmdtable)
3276 table.update(cmdtable)
3277
3277
3278 def parseconfig(config):
3279 """parse the --config options from the command line"""
3280 parsed = []
3281 for cfg in config:
3282 try:
3283 name, value = cfg.split('=', 1)
3284 section, name = name.split('.', 1)
3285 if not section or not name:
3286 raise IndexError
3287 parsed.append((section, name, value))
3288 except (IndexError, ValueError):
3289 raise util.Abort(_('malformed --config option: %s') % cfg)
3290 return parsed
3291
3278 def dispatch(args):
3292 def dispatch(args):
3279 for name in 'SIGBREAK', 'SIGHUP', 'SIGTERM':
3293 for name in 'SIGBREAK', 'SIGHUP', 'SIGTERM':
3280 num = getattr(signal, name, None)
3294 num = getattr(signal, name, None)
@@ -3306,7 +3320,7 b' def dispatch(args):'
3306
3320
3307 u.updateopts(options["verbose"], options["debug"], options["quiet"],
3321 u.updateopts(options["verbose"], options["debug"], options["quiet"],
3308 not options["noninteractive"], options["traceback"],
3322 not options["noninteractive"], options["traceback"],
3309 options["config"])
3323 parseconfig(options["config"]))
3310
3324
3311 # enter the debugger before command execution
3325 # enter the debugger before command execution
3312 if options['debugger']:
3326 if options['debugger']:
@@ -60,15 +60,8 b' class ui(object):'
60 self.debugflag = (self.debugflag or debug)
60 self.debugflag = (self.debugflag or debug)
61 self.interactive = (self.interactive and interactive)
61 self.interactive = (self.interactive and interactive)
62 self.traceback = self.traceback or traceback
62 self.traceback = self.traceback or traceback
63 for cfg in config:
63 for section, name, value in config:
64 try:
64 self.setconfig(section, name, value)
65 name, value = cfg.split('=', 1)
66 section, name = name.split('.', 1)
67 if not section or not name:
68 raise IndexError
69 self.setconfig(section, name, value)
70 except (IndexError, ValueError):
71 raise util.Abort(_('malformed --config option: %s') % cfg)
72
65
73 def readconfig(self, fn, root=None):
66 def readconfig(self, fn, root=None):
74 if isinstance(fn, basestring):
67 if isinstance(fn, basestring):
@@ -1,9 +1,9 b''
1 #!/usr/bin/env python
1 #!/usr/bin/env python
2
2
3 from mercurial import ui, util
3 from mercurial import ui, util, commands
4
4
5 testui = ui.ui()
5 testui = ui.ui()
6 testui.updateopts(config=[
6 parsed = commands.parseconfig([
7 'values.string=string value',
7 'values.string=string value',
8 'values.bool1=true',
8 'values.bool1=true',
9 'values.bool2=false',
9 'values.bool2=false',
@@ -17,6 +17,7 b' testui.updateopts(config=['
17 'interpolation.value4=%(bad)1',
17 'interpolation.value4=%(bad)1',
18 'interpolation.value5=%bad2',
18 'interpolation.value5=%bad2',
19 ])
19 ])
20 testui.updateopts(config=parsed)
20
21
21 print repr(testui.configitems('values'))
22 print repr(testui.configitems('values'))
22 print repr(testui.configitems('lists'))
23 print repr(testui.configitems('lists'))
General Comments 0
You need to be logged in to leave comments. Login now