summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSteven Knight <knight@baldmt.com>2003-04-13 13:25:12 (GMT)
committerSteven Knight <knight@baldmt.com>2003-04-13 13:25:12 (GMT)
commit06e013ecd55e950a6059ced4150304c346d1da36 (patch)
treefc8bf31a334f55bca5af8440512999baea81f4bb /src
parent5a50b311a2197c327b0b53b302801406289c1fad (diff)
downloadSCons-06e013ecd55e950a6059ced4150304c346d1da36.zip
SCons-06e013ecd55e950a6059ced4150304c346d1da36.tar.gz
SCons-06e013ecd55e950a6059ced4150304c346d1da36.tar.bz2
Add an argument for sorting Options help text.
Diffstat (limited to 'src')
-rw-r--r--src/CHANGES.txt5
-rw-r--r--src/engine/SCons/Options.py10
-rw-r--r--src/engine/SCons/OptionsTests.py40
3 files changed, 51 insertions, 4 deletions
diff --git a/src/CHANGES.txt b/src/CHANGES.txt
index 76ac21f..04b543c 100644
--- a/src/CHANGES.txt
+++ b/src/CHANGES.txt
@@ -29,6 +29,11 @@ RELEASE 0.14 - XXX
- Pass an Environment to the Options validator method, and
add an Options.Save() method.
+ From Steve Christensen:
+
+ - Add an optional sort function argument to the GenerateHelpText()
+ Options function.
+
From Steven Knight:
- Add support for Java (javac and jar).
diff --git a/src/engine/SCons/Options.py b/src/engine/SCons/Options.py
index d43be28..2aae5fc 100644
--- a/src/engine/SCons/Options.py
+++ b/src/engine/SCons/Options.py
@@ -170,7 +170,7 @@ class Options:
except IOError, x:
raise SCons.Errors.UserError, 'Error writing options to file: %s\n%s' % (filename, x)
- def GenerateHelpText(self, env):
+ def GenerateHelpText(self, env, sort=None):
"""
Generate the help text for the options.
@@ -179,7 +179,13 @@ class Options:
help_text = ""
- for option in self.options:
+ if sort:
+ options = self.options[:]
+ options.sort(lambda x,y,func=sort: func(x.key,y.key))
+ else:
+ options = self.options
+
+ for option in options:
help_text = help_text + '\n%s: %s\n default: %s\n'%(option.key, option.help, option.default)
if env.has_key(option.key):
help_text = help_text + ' actual: %s\n'%env.subst('${%s}'%option.key)
diff --git a/src/engine/SCons/OptionsTests.py b/src/engine/SCons/OptionsTests.py
index 7020787..491845e 100644
--- a/src/engine/SCons/OptionsTests.py
+++ b/src/engine/SCons/OptionsTests.py
@@ -71,7 +71,7 @@ class OptionsTestCase(unittest.TestCase):
assert o.default == None
assert o.validater == None
assert o.converter == None
- assert o.should_save == 0
+ assert o.should_save == 0
o = opts.options[1]
assert o.key == 'ANSWER'
@@ -172,6 +172,18 @@ class OptionsTestCase(unittest.TestCase):
check,
lambda x: int(x) + 12)
+ opts.Add('B',
+ 'b - alpha test',
+ "42",
+ check,
+ lambda x: int(x) + 12)
+
+ opts.Add('A',
+ 'a - alpha test',
+ "42",
+ check,
+ lambda x: int(x) + 12)
+
env = Environment()
opts.Update(env, {})
@@ -179,12 +191,36 @@ class OptionsTestCase(unittest.TestCase):
ANSWER: THE answer to THE question
default: 42
actual: 54
+
+B: b - alpha test
+ default: 42
+ actual: 54
+
+A: a - alpha test
+ default: 42
+ actual: 54
"""
text = opts.GenerateHelpText(env)
assert text == expect, text
+
+ expectAlpha = """
+A: a - alpha test
+ default: 42
+ actual: 54
+
+ANSWER: THE answer to THE question
+ default: 42
+ actual: 54
+
+B: b - alpha test
+ default: 42
+ actual: 54
+"""
+ text = opts.GenerateHelpText(env, sort=cmp)
+ assert text == expectAlpha, text
if __name__ == "__main__":
suite = unittest.makeSuite(OptionsTestCase, 'test_')
if not unittest.TextTestRunner().run(suite).wasSuccessful():
- sys.exit(1)
+ sys.exit(1)