mirror of
https://github.com/openSUSE/osc.git
synced 2024-11-10 14:56:14 +01:00
Use Field.get_callback to handle quiet/verbose and http_debug/http_full_debug options
This commit is contained in:
parent
8a38a9da82
commit
c7af0e458f
@ -564,7 +564,7 @@ class Options(OscOptions):
|
||||
description=textwrap.dedent(
|
||||
"""
|
||||
Reduce amount of printed information to bare minimum.
|
||||
Takes priority over ``verbose``.
|
||||
If enabled, automatically sets ``verbose`` to ``False``.
|
||||
"""
|
||||
),
|
||||
) # type: ignore[assignment]
|
||||
@ -574,8 +574,10 @@ class Options(OscOptions):
|
||||
description=textwrap.dedent(
|
||||
"""
|
||||
Increase amount of printed information to stdout.
|
||||
Automatically set to ``False`` when ``quiet`` is enabled.
|
||||
"""
|
||||
),
|
||||
get_callback=lambda conf, value: False if conf.quiet else value,
|
||||
) # type: ignore[assignment]
|
||||
|
||||
debug: bool = Field(
|
||||
@ -592,8 +594,10 @@ class Options(OscOptions):
|
||||
description=textwrap.dedent(
|
||||
"""
|
||||
Print HTTP traffic to stderr.
|
||||
Automatically set to ``True`` when``http_full_debug`` is enabled.
|
||||
"""
|
||||
),
|
||||
get_callback=lambda conf, value: True if conf.http_full_debug else value,
|
||||
) # type: ignore[assignment]
|
||||
|
||||
http_full_debug: bool = Field(
|
||||
@ -601,6 +605,7 @@ class Options(OscOptions):
|
||||
description=textwrap.dedent(
|
||||
"""
|
||||
[CAUTION!] Print HTTP traffic incl. authentication data to stderr.
|
||||
If enabled, automatically sets ``http_debug`` to ``True``.
|
||||
"""
|
||||
),
|
||||
) # type: ignore[assignment]
|
||||
@ -1821,7 +1826,6 @@ def get_config(override_conffile=None,
|
||||
overrides["http_debug"] = override_http_debug
|
||||
|
||||
if override_http_full_debug is not None:
|
||||
overrides["http_debug"] = override_http_full_debug or overrides["http_debug"]
|
||||
overrides["http_full_debug"] = override_http_full_debug
|
||||
|
||||
if override_traceback is not None:
|
||||
|
@ -434,6 +434,33 @@ class TestExampleConfig(unittest.TestCase):
|
||||
self.assertEqual(self.config["apiurl_aliases"], expected)
|
||||
|
||||
|
||||
class TestOverrides(unittest.TestCase):
|
||||
def test_verbose(self):
|
||||
self.options = osc.conf.Options()
|
||||
self.assertEqual(self.options.quiet, False)
|
||||
self.assertEqual(self.options.verbose, False)
|
||||
|
||||
self.options.quiet = True
|
||||
self.options.verbose = True
|
||||
self.assertEqual(self.options.quiet, True)
|
||||
# ``verbose`` is forced to ``False`` by the ``quiet`` option
|
||||
self.assertEqual(self.options.verbose, False)
|
||||
|
||||
self.options.quiet = False
|
||||
self.assertEqual(self.options.quiet, False)
|
||||
self.assertEqual(self.options.verbose, True)
|
||||
|
||||
def test_http_debug(self):
|
||||
self.options = osc.conf.Options()
|
||||
self.assertEqual(self.options.http_debug, False)
|
||||
self.assertEqual(self.options.http_full_debug, False)
|
||||
|
||||
self.options.http_full_debug = True
|
||||
# ``http_debug`` forced to ``True`` by the ``http_full_debug`` option
|
||||
self.assertEqual(self.options.http_debug, True)
|
||||
self.assertEqual(self.options.http_full_debug, True)
|
||||
|
||||
|
||||
class TestFromParent(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.options = osc.conf.Options()
|
||||
|
Loading…
Reference in New Issue
Block a user