~testdoc-dev/testdoc/trunk.git

« back to all changes in this revision

Viewing changes to bin/testdoc

  • Committer: Andrew Bennetts
  • Date: 2010-09-06 12:10:13 UTC
  • mto: This revision was merged to the branch mainline in revision 19.
  • Revision ID: git-v1:054ef0553a67a5f7dd43ddf29af8e864ae407be2
Use optparse to add a --format option to switch between Moin or ReST output.

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
    return obj
28
28
 
29
29
 
 
30
def make_options():
 
31
    from optparse import OptionParser
 
32
    parser = OptionParser(
 
33
        usage="usage: %prog [options] <fully-qualified module name>")
 
34
    format_choices = sorted(formats.keys())
 
35
    parser.add_option("-f", "--format", dest="format",
 
36
        choices=format_choices, metavar="FORMAT",
 
37
        help="Format to emit.  One of: " + ', '.join(format_choices),
 
38
        default="moin")
 
39
    return parser
 
40
 
 
41
 
 
42
formats = {
 
43
    'moin': formatter.WikiFormatter,
 
44
    'rest': formatter.ReSTFormatter,
 
45
    }
 
46
 
 
47
 
30
48
def main():
31
 
    if len(sys.argv) != 2:
32
 
        print usage()
33
 
        sys.exit(2)
34
 
    try:
35
 
        module = string_to_module(sys.argv[1])
36
 
    except:
37
 
        print usage()
38
 
        raise
39
 
    format = formatter.ReSTFormatter(sys.stdout)
40
 
    #format = formatter.WikiFormatter(sys.stdout)
 
49
    parser = make_options()
 
50
    (options, args) = parser.parse_args()
 
51
    format = formats[options.format](sys.stdout)
41
52
    doc = documenter.Documenter(format)
 
53
    module = string_to_module(args[0])
42
54
    finder.find_tests(doc, module)
43
55
 
44
56