Index: tools/html-json-doc/bin/htmlJsonDoc.dart |
diff --git a/tools/html-json-doc/bin/htmlJsonDoc.dart b/tools/html-json-doc/bin/htmlJsonDoc.dart |
new file mode 100644 |
index 0000000000000000000000000000000000000000..4884b86f6ec626eea0c98865818064c6325bc693 |
--- /dev/null |
+++ b/tools/html-json-doc/bin/htmlJsonDoc.dart |
@@ -0,0 +1,73 @@ |
+/** |
+ * TODO(amouravski): Document stuff here. |
+ */ |
+ |
+import 'dart:io'; |
+ |
+import '../lib/HtmlToJson.dart' as htmlToJson; |
+import '../lib/JsonToHtml.dart' as jsonToHtml; |
+import '../../../pkg/args/lib/args.dart'; |
+ |
+// Need this because ArgParser.getUsage doesn't show command invocation. |
+final USAGE = 'Usage htmlJsonDoc [options] --mode=<mode> <HTML.dart directory> ' |
Bob Nystrom
2012/11/26 22:00:19
Make this "const" or rename to "usage".
Andrei Mouravski
2012/11/27 03:11:45
Done.
|
+ '<json path>\n[options] include:'; |
+final argParser = htmlJsonDocArgParser(); |
+ |
+main() { |
+ final args = new Options().arguments; |
+ |
+ if (args.isEmpty) { |
+ printUsage('No arguments provided.'); |
+ return; |
+ } |
+ |
+ var htmlToJsonMode; |
+ |
+ final argResults = argParser.parse(args); |
+ try { |
+ htmlToJsonMode = argResults['mode'] == 'html-to-json'; |
+ } on ArgumentError catch (e) { |
Bob Nystrom
2012/11/26 22:00:19
You shouldn't catch ArgumentError. (In general, yo
Andrei Mouravski
2012/11/27 03:11:45
Done.
|
+ printUsage('Mode is a required option.'); |
+ } |
+ |
+ var htmlPath = new Path.fromNative(argResults.rest[0]); |
+ var jsonPath = new Path.fromNative(argResults.rest[1]); |
+ |
+ if (htmlPath == null || jsonPath == null) { |
Bob Nystrom
2012/11/26 22:00:19
How would these ever be null? Maybe just:
if (ar
Andrei Mouravski
2012/11/27 03:11:45
Done.
|
+ printUsage('Insufficient arguments.'); |
+ return; |
+ } |
+ |
+ var convertFuture; |
+ if (htmlToJsonMode) { |
+ convertFuture = htmlToJson.convert(htmlPath, jsonPath); |
+ } else { |
+ convertFuture = jsonToHtml.convert(htmlPath, jsonPath); |
+ } |
+ |
+ convertFuture.then((anyErrors) { |
+ print('Completed ${anyErrors ? "with" : "without"} errrors.'); |
Bob Nystrom
2012/11/26 22:00:19
Arrrrr, ye have too many Rs in yer errors!
Andrei Mouravski
2012/11/27 03:11:45
Done. Amusingly I was trying to debug some of my o
|
+ }); |
+} |
+ |
+/// Prints the usage of the tool. [message] is printed if provided. |
+void printUsage([String message]) { |
+ print(message); |
+ print(USAGE); |
+ print(argParser.getUsage()); |
+} |
+ |
+ArgParser htmlJsonDocArgParser() { |
+ final argParser = new ArgParser(); |
+ |
+ argParser.addOption('mode', abbr: 'm', |
+ help: '(Required) Convert from HTML docs to JSON or vice versa.', |
+ allowed: ['html-to-json', 'json-to-html'], allowedHelp: { |
+ 'html-to-json': 'Processes all HTML .dart files at given\n' |
+ 'location and outputs JSON.', |
+ 'json-to-html': 'Takes JSON file at location and inserts docs into\n' |
+ 'HTML .dart files.'} |
Bob Nystrom
2012/11/26 22:00:19
Yay usage help!
Andrei Mouravski
2012/11/27 03:11:45
P.S. Copied wholesale from pub I think. Maybe one
|
+ ); |
+ |
+ return argParser; |
+} |