[pypy-svn] r38885 - in pypy/dist/pypy/config: . test
cfbolz at codespeak.net
cfbolz at codespeak.net
Thu Feb 15 14:52:22 CET 2007
Author: cfbolz
Date: Thu Feb 15 14:52:21 2007
New Revision: 38885
Modified:
pypy/dist/pypy/config/makerestdoc.py
pypy/dist/pypy/config/test/test_makerestdoc.py
Log:
introduce a way to document all the command line options
Modified: pypy/dist/pypy/config/makerestdoc.py
==============================================================================
--- pypy/dist/pypy/config/makerestdoc.py (original)
+++ pypy/dist/pypy/config/makerestdoc.py Thu Feb 15 14:52:21 2007
@@ -1,6 +1,6 @@
import py
from py.__.rest.rst import Rest, Paragraph, Strong, ListItem, Title, Link
-from py.__.rest.rst import Directive, Em
+from py.__.rest.rst import Directive, Em, Quote, Text
from pypy.config.config import ChoiceOption, BoolOption, StrOption, IntOption
from pypy.config.config import FloatOption, OptionDescription, Option, Config
@@ -13,7 +13,13 @@
else:
return opt._name
-
+
+def get_cmdline(cmdline, fullpath):
+ if cmdline is DEFAULT_OPTION_NAME:
+ return '--%s' % (fullpath.replace('.', '-'),)
+ else:
+ return cmdline
+
class __extend__(Option):
def make_rest_doc(self, path=""):
@@ -26,10 +32,7 @@
ListItem(Strong("name:"), self._name),
ListItem(Strong("description:"), self.doc))
if self.cmdline is not None:
- if self.cmdline is DEFAULT_OPTION_NAME:
- cmdline = '--%s' % (fullpath.replace('.', '-'),)
- else:
- cmdline = self.cmdline
+ cmdline = get_cmdline(self.cmdline, fullpath)
result.add(ListItem(Strong("command-line:"), cmdline))
return result
@@ -159,3 +162,25 @@
curr = new
return content
+
+def make_cmdline_overview(descr):
+ content = Rest(
+ Title("Overwiew of Command Line Options for '%s'" % (descr._name, ),
+ abovechar="=", belowchar="="))
+ cmdlines = []
+ config = Config(descr)
+ for path in config.getpaths(include_groups=False):
+ subconf, step = config._cfgimpl_get_home_by_path(path)
+ fullpath = (descr._name + "." + path)
+ prefix = fullpath.rsplit(".", 1)[0]
+ subdescr = getattr(subconf._cfgimpl_descr, step)
+ cmdline = get_cmdline(subdescr.cmdline, fullpath)
+ if cmdline is not None:
+ cmdlines.append((cmdline, fullpath, subdescr))
+ cmdlines.sort(key=lambda t: t[0].strip("-"))
+ for cmdline, fullpath, subdescr in cmdlines:
+ content.add(ListItem(Link(cmdline + ":", fullpath + ".html"),
+ Text(subdescr.doc)))
+ return content
+
+
Modified: pypy/dist/pypy/config/test/test_makerestdoc.py
==============================================================================
--- pypy/dist/pypy/config/test/test_makerestdoc.py (original)
+++ pypy/dist/pypy/config/test/test_makerestdoc.py Thu Feb 15 14:52:21 2007
@@ -1,5 +1,5 @@
from pypy.config.config import *
-import pypy.config.makerestdoc
+from pypy.config.makerestdoc import make_cmdline_overview
from py.__.doc.conftest import restcheck
@@ -65,5 +65,19 @@
result = generate_html(descr)
assert "more doc" in result[""]
-
-
+def test_cmdline_overview():
+ descr = OptionDescription("foo", "doc", [
+ ChoiceOption("bar", "more doc", ["a", "b", "c"]),
+ OptionDescription("sub", "nope", [
+ ChoiceOption("subbar", "", ["d", "f"]),
+ BoolOption("boolean", "this is a boolean", default=False,
+ cmdline="-b --with-b")
+ ]),
+ StrOption("str", "string option!", default="strange"),
+ IntOption("int", "integer option", default=42),
+ FloatOption("float", "float option", default=py.std.math.pi),
+ ArbitraryOption("surprise", "special", defaultfactory=int),
+ ])
+ generate_html(descr)
+ c = make_cmdline_overview(descr)
+ checkrest(c.text(), "index.txt")
More information about the Pypy-commit
mailing list