Mercurial > hg-stable
changeset 3346:1700a103458e
move the parsing of --config options to commands.py
author | Alexis S. L. Carvalho <alexis@cecm.usp.br> |
---|---|
date | Tue, 10 Oct 2006 18:43:20 -0300 |
parents | a09be4317f9c |
children | bce7c1b4c1c8 |
files | mercurial/commands.py mercurial/ui.py tests/test-ui-config |
diffstat | 3 files changed, 20 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/commands.py Tue Oct 10 18:43:20 2006 -0300 +++ b/mercurial/commands.py Tue Oct 10 18:43:20 2006 -0300 @@ -3275,6 +3275,20 @@ ui.warn(_("module %s overrides %s\n") % (name, t)) table.update(cmdtable) +def parseconfig(config): + """parse the --config options from the command line""" + parsed = [] + for cfg in config: + try: + name, value = cfg.split('=', 1) + section, name = name.split('.', 1) + if not section or not name: + raise IndexError + parsed.append((section, name, value)) + except (IndexError, ValueError): + raise util.Abort(_('malformed --config option: %s') % cfg) + return parsed + def dispatch(args): for name in 'SIGBREAK', 'SIGHUP', 'SIGTERM': num = getattr(signal, name, None) @@ -3306,7 +3320,7 @@ u.updateopts(options["verbose"], options["debug"], options["quiet"], not options["noninteractive"], options["traceback"], - options["config"]) + parseconfig(options["config"])) # enter the debugger before command execution if options['debugger']:
--- a/mercurial/ui.py Tue Oct 10 18:43:20 2006 -0300 +++ b/mercurial/ui.py Tue Oct 10 18:43:20 2006 -0300 @@ -60,15 +60,8 @@ self.debugflag = (self.debugflag or debug) self.interactive = (self.interactive and interactive) self.traceback = self.traceback or traceback - for cfg in config: - try: - name, value = cfg.split('=', 1) - section, name = name.split('.', 1) - if not section or not name: - raise IndexError - self.setconfig(section, name, value) - except (IndexError, ValueError): - raise util.Abort(_('malformed --config option: %s') % cfg) + for section, name, value in config: + self.setconfig(section, name, value) def readconfig(self, fn, root=None): if isinstance(fn, basestring):
--- a/tests/test-ui-config Tue Oct 10 18:43:20 2006 -0300 +++ b/tests/test-ui-config Tue Oct 10 18:43:20 2006 -0300 @@ -1,9 +1,9 @@ #!/usr/bin/env python -from mercurial import ui, util +from mercurial import ui, util, commands testui = ui.ui() -testui.updateopts(config=[ +parsed = commands.parseconfig([ 'values.string=string value', 'values.bool1=true', 'values.bool2=false', @@ -17,6 +17,7 @@ 'interpolation.value4=%(bad)1', 'interpolation.value5=%bad2', ]) +testui.updateopts(config=parsed) print repr(testui.configitems('values')) print repr(testui.configitems('lists'))