Rev 6165: Follow the lead of other 'global' options which are not declared in option.py but handled in bzrlib.commands.run_bzr instead. in file:///home/vila/src/bzr/bugs/491196-cmdline-options/
Vincent Ladeuil
v.ladeuil+lp at free.fr
Tue Sep 27 13:18:53 UTC 2011
At file:///home/vila/src/bzr/bugs/491196-cmdline-options/
------------------------------------------------------------
revno: 6165
revision-id: v.ladeuil+lp at free.fr-20110927131853-bafk1zx2zyv5otu1
parent: v.ladeuil+lp at free.fr-20110927095823-zxf9fqimx5j44hdb
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: 491196-cmdline-options
timestamp: Tue 2011-09-27 15:18:53 +0200
message:
Follow the lead of other 'global' options which are not declared in option.py but handled in bzrlib.commands.run_bzr instead.
-------------- next part --------------
=== modified file 'bzrlib/commands.py'
--- a/bzrlib/commands.py 2011-09-27 09:49:22 +0000
+++ b/bzrlib/commands.py 2011-09-27 13:18:53 +0000
@@ -663,15 +663,6 @@
opts['quiet'] = trace.is_quiet()
elif opts.has_key('quiet'):
del opts['quiet']
- overrides = None
- try:
- overrides = opts.pop('override_config')
- except KeyError:
- # No overrides were specified
- pass
- if overrides:
- bzrlib.global_state.cmdline_overrides._from_cmdline(overrides)
-
# mix arguments and options into one dictionary
cmdargs = _match_argform(self.name(), self.takes_args, args)
cmdopts = {}
@@ -1048,6 +1039,7 @@
argv_copy = []
i = 0
+ override_config = []
while i < len(argv):
a = argv[i]
if a == '--profile':
@@ -1076,10 +1068,17 @@
pass # already handled in startup script Bug #588277
elif a.startswith('-D'):
debug.debug_flags.add(a[2:])
+ elif a.startswith('-O'):
+ override_config.append(a[2:])
+ elif a.startswith('--override-config'):
+ i += 1
+ override_config.append(argv[i])
else:
argv_copy.append(a)
i += 1
+ bzrlib.global_state.cmdline_overrides._from_cmdline(override_config)
+
debug.set_debug_flags_from_config()
if not opt_no_plugins:
=== modified file 'bzrlib/config.py'
--- a/bzrlib/config.py 2011-09-27 09:49:22 +0000
+++ b/bzrlib/config.py 2011-09-27 13:18:53 +0000
@@ -2654,6 +2654,8 @@
super(CommandLineSection, self).__init__('cmdline-overrides', opts)
def _from_cmdline(self, overrides):
+ # Reset before accepting new definitions
+ self.options.clear()
for over in overrides:
try:
name, value = over.split('=', 1)
=== modified file 'bzrlib/help_topics/__init__.py'
--- a/bzrlib/help_topics/__init__.py 2011-09-07 16:32:11 +0000
+++ b/bzrlib/help_topics/__init__.py 2011-09-27 13:18:53 +0000
@@ -312,24 +312,27 @@
These options may be used with any command, and may appear in front of any
command. (e.g. ``bzr --profile help``).
-
---version Print the version number. Must be supplied before the command.
---no-aliases Do not process command aliases when running this command.
---builtin Use the built-in version of a command, not the plugin version.
- This does not suppress other plugin effects.
---no-plugins Do not process any plugins.
---no-l10n Do not translate messages.
---concurrency Number of processes that can be run concurrently (selftest).
-
---profile Profile execution using the hotshot profiler.
---lsprof Profile execution using the lsprof profiler.
---lsprof-file Profile execution using the lsprof profiler, and write the
- results to a specified file. If the filename ends with ".txt",
- text format will be used. If the filename either starts with
- "callgrind.out" or end with ".callgrind", the output will be
- formatted for use with KCacheGrind. Otherwise, the output
- will be a pickle.
---coverage Generate line coverage report in the specified directory.
+
+--version Print the version number. Must be supplied before the command.
+--no-aliases Do not process command aliases when running this command.
+--builtin Use the built-in version of a command, not the plugin version.
+ This does not suppress other plugin effects.
+--no-plugins Do not process any plugins.
+--no-l10n Do not translate messages.
+--concurrency Number of processes that can be run concurrently (selftest).
+
+--profile Profile execution using the hotshot profiler.
+--lsprof Profile execution using the lsprof profiler.
+--lsprof-file Profile execution using the lsprof profiler, and write the
+ results to a specified file. If the filename ends with
+ ".txt", text format will be used. If the filename either
+ starts with "callgrind.out" or end with ".callgrind", the
+ output will be formatted for use with KCacheGrind. Otherwise,
+ the output will be a pickle.
+--coverage Generate line coverage report in the specified directory.
+--override-config Override a config option for the duration of the command.
+ This can be used multiple times if several options need to
+ be overridden. The short form is ``-Oname=value``.
See http://doc.bazaar.canonical.com/developers/profiling.html for more
information on profiling.
=== modified file 'bzrlib/option.py'
--- a/bzrlib/option.py 2011-09-27 09:58:23 +0000
+++ b/bzrlib/option.py 2011-09-27 13:18:53 +0000
@@ -537,10 +537,6 @@
# Declare the standard options
_standard_option('help', short_name='h',
help='Show help message.')
-_standard_list_option('override-config', short_name='O', type=unicode,
- hidden=True,
- help='Override a configuration option value,'
- ' e.g. -Oname=value')
_standard_option('quiet', short_name='q',
help="Only display errors and warnings.",
custom_callback=_verbosity_level_callback)
=== modified file 'bzrlib/tests/test_commands.py'
--- a/bzrlib/tests/test_commands.py 2011-09-26 15:40:02 +0000
+++ b/bzrlib/tests/test_commands.py 2011-09-27 13:18:53 +0000
@@ -45,15 +45,10 @@
self.assertLength(0, commands_without_help)
def test_command_see_config_overrides(self):
- class cmd_my_cmd(commands.Command):
-
- def run(self):
- c = config.GlobalStack()
- val = c.get('xx')
- return val
-
- cmd = cmd_my_cmd()
- self.assertEquals('12', cmd.run_argv_aliases(['-Oxx=12']))
+ self.run_bzr(['rocks', '-Oxx=12', '--override-config', 'yy=foo'])
+ c = config.GlobalStack()
+ self.assertEquals('12', c.get('xx'))
+ self.assertEquals('foo', c.get('yy'))
def test_display_command(self):
"""EPIPE message is selectively suppressed"""
=== modified file 'bzrlib/tests/test_help.py'
--- a/bzrlib/tests/test_help.py 2011-09-26 15:40:02 +0000
+++ b/bzrlib/tests/test_help.py 2011-09-27 13:18:53 +0000
@@ -49,13 +49,10 @@
Usage: bzr WithSeeAlso
Options:
- -O ARG, --override-config=ARG
- Override a configuration option value, e.g.
- -Oname=value
- --usage Show usage message and options.
- -q, --quiet Only display errors and warnings.
- -v, --verbose Display more information.
- -h, --help Show help message.
+ --usage Show usage message and options.
+ -q, --quiet Only display errors and warnings.
+ -v, --verbose Display more information.
+ -h, --help Show help message.
See also: bar, foo
''',
@@ -70,13 +67,10 @@
Usage: bzr Demo
Options:
- -O ARG, --override-config=ARG
- Override a configuration option value, e.g.
- -Oname=value
- --usage Show usage message and options.
- -q, --quiet Only display errors and warnings.
- -v, --verbose Display more information.
- -h, --help Show help message.
+ --usage Show usage message and options.
+ -q, --quiet Only display errors and warnings.
+ -v, --verbose Display more information.
+ -h, --help Show help message.
''',
cmd_Demo())
@@ -86,7 +80,7 @@
'Purpose: A sample command.\n'
'Usage: bzr Demo')
self.assertEndsWith(helptext,
- ' -h, --help Show help message.\n\n')
+ ' -h, --help Show help message.\n\n')
def test_command_with_additional_see_also(self):
class cmd_WithSeeAlso(commands.Command):
@@ -96,9 +90,9 @@
helptext = cmd.get_help_text(['gam'])
self.assertEndsWith(
helptext,
- ' -q, --quiet Only display errors and warnings.\n'
- ' -v, --verbose Display more information.\n'
- ' -h, --help Show help message.\n'
+ ' -q, --quiet Only display errors and warnings.\n'
+ ' -v, --verbose Display more information.\n'
+ ' -h, --help Show help message.\n'
'\n'
'See also: bar, foo, gam\n')
@@ -109,9 +103,9 @@
helptext = cmd.get_help_text(['gam'])
self.assertEndsWith(
helptext,
- ' -q, --quiet Only display errors and warnings.\n'
- ' -v, --verbose Display more information.\n'
- ' -h, --help Show help message.\n'
+ ' -q, --quiet Only display errors and warnings.\n'
+ ' -v, --verbose Display more information.\n'
+ ' -h, --help Show help message.\n'
'\n'
'See also: gam\n')
@@ -149,13 +143,10 @@
Usage: bzr Demo
Options:
- -O ARG, --override-config=ARG
- Override a configuration option value, e.g.
- -Oname=value
- --usage Show usage message and options.
- -q, --quiet Only display errors and warnings.
- -v, --verbose Display more information.
- -h, --help Show help message.
+ --usage Show usage message and options.
+ -q, --quiet Only display errors and warnings.
+ -v, --verbose Display more information.
+ -h, --help Show help message.
Examples:
Example 1:
@@ -178,13 +169,10 @@
:Usage: bzr Demo
:Options:
- -O ARG, --override-config=ARG
- Override a configuration option value, e.g.
- -Oname=value
- --usage Show usage message and options.
- -q, --quiet Only display errors and warnings.
- -v, --verbose Display more information.
- -h, --help Show help message.
+ --usage Show usage message and options.
+ -q, --quiet Only display errors and warnings.
+ -v, --verbose Display more information.
+ -h, --help Show help message.
:Examples:
Example 1::
@@ -223,13 +211,10 @@
Usage: bzr Demo
Options:
- -O ARG, --override-config=ARG
- Override a configuration option value, e.g.
- -Oname=value
- --usage Show usage message and options.
- -q, --quiet Only display errors and warnings.
- -v, --verbose Display more information.
- -h, --help Show help message.
+ --usage Show usage message and options.
+ -q, --quiet Only display errors and warnings.
+ -v, --verbose Display more information.
+ -h, --help Show help message.
Description:
Blah blah blah.
@@ -247,13 +232,10 @@
Usage: bzr Demo
Options:
- -O ARG, --override-config=ARG
- Override a configuration option value, e.g.
- -Oname=value
- --usage Show usage message and options.
- -q, --quiet Only display errors and warnings.
- -v, --verbose Display more information.
- -h, --help Show help message.
+ --usage Show usage message and options.
+ -q, --quiet Only display errors and warnings.
+ -v, --verbose Display more information.
+ -h, --help Show help message.
See bzr help Demo for more details and examples.
@@ -286,13 +268,10 @@
Usage: bzr Demo
Options:
- -O ARG, --override-config=ARG
- Override a configuration option value, e.g.
- -Oname=value
- --usage Show usage message and options.
- -q, --quiet Only display errors and warnings.
- -v, --verbose Display more information.
- -h, --help Show help message.
+ --usage Show usage message and options.
+ -q, --quiet Only display errors and warnings.
+ -v, --verbose Display more information.
+ -h, --help Show help message.
Description:
Blah blah blah.
@@ -334,13 +313,10 @@
Options:
- -O ARG, --override-config=ARG
- Override a configuration option value, e.g.
- -Oname=value
- --usage Show usage message and options.
- -q, --quiet Only display errors and warnings.
- -v, --verbose Display more information.
- -h, --help Show help message.
+ --usage Show usage message and options.
+ -q, --quiet Only display errors and warnings.
+ -v, --verbose Display more information.
+ -h, --help Show help message.
Description:
Blah blah blah.
@@ -382,13 +358,10 @@
}}zz{{:Usage: bzr WithSeeAlso
}}
zz{{:Options:
- -O ARG, --override-config=ARG
- zz{{Override a configuration option value, e.g.
- -Oname=value}}
- --usage zz{{Show usage message and options.}}
- -q, --quiet zz{{Only display errors and warnings.}}
- -v, --verbose zz{{Display more information.}}
- -h, --help zz{{Show help message.}}
+ --usage zz{{Show usage message and options.}}
+ -q, --quiet zz{{Only display errors and warnings.}}
+ -v, --verbose zz{{Display more information.}}
+ -h, --help zz{{Show help message.}}
}}
zz{{:See also: bar, foo}}
''',
@@ -403,13 +376,10 @@
}}zz{{:Usage: bzr Demo
}}
zz{{:Options:
- -O ARG, --override-config=ARG
- zz{{Override a configuration option value, e.g.
- -Oname=value}}
- --usage zz{{Show usage message and options.}}
- -q, --quiet zz{{Only display errors and warnings.}}
- -v, --verbose zz{{Display more information.}}
- -h, --help zz{{Show help message.}}
+ --usage zz{{Show usage message and options.}}
+ -q, --quiet zz{{Only display errors and warnings.}}
+ -v, --verbose zz{{Display more information.}}
+ -h, --help zz{{Show help message.}}
}}
''',
cmd_Demo())
@@ -422,9 +392,9 @@
helptext = cmd.get_help_text(['gam'])
self.assertEndsWith(
helptext,'''\
- -q, --quiet zz{{Only display errors and warnings.}}
- -v, --verbose zz{{Display more information.}}
- -h, --help zz{{Show help message.}}
+ -q, --quiet zz{{Only display errors and warnings.}}
+ -v, --verbose zz{{Display more information.}}
+ -h, --help zz{{Show help message.}}
}}
zz{{:See also: bar, foo, gam}}
''')
@@ -437,13 +407,10 @@
self.assertEndsWith(
helptext, '''\
zz{{:Options:
- -O ARG, --override-config=ARG
- zz{{Override a configuration option value, e.g.
- -Oname=value}}
- --usage zz{{Show usage message and options.}}
- -q, --quiet zz{{Only display errors and warnings.}}
- -v, --verbose zz{{Display more information.}}
- -h, --help zz{{Show help message.}}
+ --usage zz{{Show usage message and options.}}
+ -q, --quiet zz{{Only display errors and warnings.}}
+ -v, --verbose zz{{Display more information.}}
+ -h, --help zz{{Show help message.}}
}}
zz{{:See also: gam}}
''')
@@ -473,13 +440,10 @@
}}zz{{:Usage: bzr Demo
}}
zz{{:Options:
- -O ARG, --override-config=ARG
- zz{{Override a configuration option value, e.g.
- -Oname=value}}
- --usage zz{{Show usage message and options.}}
- -q, --quiet zz{{Only display errors and warnings.}}
- -v, --verbose zz{{Display more information.}}
- -h, --help zz{{Show help message.}}
+ --usage zz{{Show usage message and options.}}
+ -q, --quiet zz{{Only display errors and warnings.}}
+ -v, --verbose zz{{Display more information.}}
+ -h, --help zz{{Show help message.}}
}}
Description:
zz{{zz{{Blah blah blah.}}
@@ -519,13 +483,10 @@
}}
zz{{:Options:
- -O ARG, --override-config=ARG
- zz{{Override a configuration option value, e.g.
- -Oname=value}}
- --usage zz{{Show usage message and options.}}
- -q, --quiet zz{{Only display errors and warnings.}}
- -v, --verbose zz{{Display more information.}}
- -h, --help zz{{Show help message.}}
+ --usage zz{{Show usage message and options.}}
+ -q, --quiet zz{{Only display errors and warnings.}}
+ -v, --verbose zz{{Display more information.}}
+ -h, --help zz{{Show help message.}}
}}
Description:
zz{{zz{{Blah blah blah.}}
=== modified file 'bzrlib/tests/test_options.py'
--- a/bzrlib/tests/test_options.py 2011-09-26 15:40:02 +0000
+++ b/bzrlib/tests/test_options.py 2011-09-27 13:18:53 +0000
@@ -44,19 +44,16 @@
# to cmd_commit, when they are meant to be about option parsing in
# general.
self.assertEqual(
- ([], {'author': [], 'exclude': [], 'fixes': [], 'help': True,
- 'override_config': []}),
+ ([], {'author': [], 'exclude': [], 'fixes': [], 'help': True}),
parse_args(cmd_commit(), ['--help']))
self.assertEqual(
- ([], {'author': [], 'exclude': [], 'fixes': [], 'message': 'biter',
- 'override_config': []}),
+ ([], {'author': [], 'exclude': [], 'fixes': [], 'message': 'biter'}),
parse_args(cmd_commit(), ['--message=biter']))
def test_no_more_opts(self):
"""Terminated options"""
self.assertEqual(
- (['-file-with-dashes'], {'author': [], 'exclude': [], 'fixes': [],
- 'override_config': []}),
+ (['-file-with-dashes'], {'author': [], 'exclude': [], 'fixes': []}),
parse_args(cmd_commit(), ['--', '-file-with-dashes']))
def test_option_help(self):
More information about the bazaar-commits
mailing list