source: josm/trunk/utils/org/openstreetmap/josm/HelpTopicReporter.groovy@ 2739

Last change on this file since 2739 was 2324, checked in by Gubaer, 14 years ago

Two groovy scripts for extracting declared help topics from the JOSM source and for creating a trac wiki report

File size: 2.5 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm;
3
4import java.io.BufferedReader;
5
6/**
7 * Creates a help topics report for the JOSM trac wiki.
8 *
9 */
10public class HelpTopicReporter {
11
12 private PrintWriter writer
13 private List<String> files = []
14 private String outputFile = null
15 private PrintWriter outputWriter = null
16
17 def String formatLine(String line) {
18 def fields = line.split("\t")
19 def repositoryPath = fields[3].replace(".", "/") + "/" + fields[1]
20 // each line is a table row according to the simple trac table syntax
21 //
22 return "||[wiki:/Help${fields[4]} ${fields[4]}]||${fields[3]}||[source:/trunk/src/${repositoryPath}#L${fields[2]} ${fields[1]}]||"
23 }
24
25 def process(BufferedReader reader) {
26 reader.eachLine {
27 String line ->
28 writer.println formatLine(line)
29 }
30 }
31
32 def showHelp() {
33 println "groovy org.openstreetmap.josm.HelpTopicReporter [options] file*"
34 println "Options:"
35 println " --help|-h show help information"
36 println " -output-file|-o file write to output file"
37 println "Reads from stdin if no input file(s) in the argument list"
38 }
39
40 def run(String[] args) {
41 def i = 0
42 while(i<args.length) {
43 def arg = args[i]
44 if (arg == "-h" || arg == "--help") {
45 showHelp()
46 System.exit(0)
47 } else if (arg == "-o" || arg == "--output-file") {
48 i++
49 if (i >= args.length) {
50 System.err.println "Missing argument for option '${args[i-1]}'"
51 System.exit(1)
52 }
53 outputFile = args[i]
54 outputWriter = new PrintWriter(new FileWriter(outputFile))
55 i++
56 } else {
57 files.add(arg)
58 i++
59 }
60
61 }
62 if (outputFile == null) {
63 outputWriter = new PrintWriter(new OutputStreamWriter(System.out))
64 }
65
66 if (! files.isEmpty()) {
67 files.each { process(new BufferedReader(new FileReader(new File(it)))) }
68 } else {
69 process(new BufferedReader(new InputStreamReader(System.in)))
70 }
71 outputWriter.flush()
72 if (outputFile != null) {
73 outputWriter.close()
74 }
75 }
76
77 static public void main(String[] args) {
78 new HelpTopicReporter().run(args)
79 }
80}
Note: See TracBrowser for help on using the repository browser.