From 634012761e422d6f0fdd69021b4e6407826c7b4a Mon Sep 17 00:00:00 2001 From: Stephen Finucane Date: Tue, 19 Apr 2016 10:57:23 +0100 Subject: [PATCH] Add 'DEPRECATED: ' prefix for deprecated opts 'f5e2fab' added support for a deprecated reason. However, there is are a number of cases where users still prefix option help strings with 'DEPRECATED: ', presumably as this provides a more visible indicator of the deprecation. Rather than leaving it up to users to do this manually, prefix these strings automatically. A check is included to ensure duplication does not occur. Change-Id: I79c20d31f664d01534b6798b134b2c3fd363faec --- oslo_config/generator.py | 10 ++++++++-- oslo_config/tests/test_generator.py | 6 +++--- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/oslo_config/generator.py b/oslo_config/generator.py index 3654e4a6..ed66cf0e 100644 --- a/oslo_config/generator.py +++ b/oslo_config/generator.py @@ -171,9 +171,15 @@ class _OptFormatter(object): option_type = getattr(opt, 'type', None) opt_type = getattr(option_type, 'type_name', 'unknown value') + opt_prefix = '' + if (opt.deprecated_for_removal and + not opt.help.startswith('DEPRECATED')): + opt_prefix = 'DEPRECATED: ' + if opt.help: - help_text = u'%s (%s)' % (opt.help, - opt_type) + help_text = u'%s%s (%s)' % (opt_prefix, + opt.help, + opt_type) else: help_text = u'(%s)' % opt_type lines = self._format_help(help_text) diff --git a/oslo_config/tests/test_generator.py b/oslo_config/tests/test_generator.py index 7e63824b..ae3b36cf 100644 --- a/oslo_config/tests/test_generator.py +++ b/oslo_config/tests/test_generator.py @@ -91,7 +91,7 @@ class GeneratorTestCase(base.BaseTestCase): deprecated_for_removal=True, deprecated_reason='This was supposed to work but it really, ' 'really did not. Always buy house insurance.', - help='Turn off stove'), + help='DEPRECATED: Turn off stove'), 'deprecated_group': cfg.StrOpt('bar', deprecated_group='group1', deprecated_name='foobar', @@ -427,7 +427,7 @@ class GeneratorTestCase(base.BaseTestCase): # From test # -# deprecated for removal (string value) +# DEPRECATED: deprecated for removal (string value) # This option is deprecated for removal. # Its value may be silently ignored in the future. #bar = @@ -445,7 +445,7 @@ class GeneratorTestCase(base.BaseTestCase): # From test # -# Turn off stove (boolean value) +# DEPRECATED: Turn off stove (boolean value) # This option is deprecated for removal. # Its value may be silently ignored in the future. # Reason: This was supposed to work but it really, really did not.