OLD | NEW |
---|---|
(Empty) | |
1 /** | |
2 * TODO(amouravski): Document stuff here. | |
3 */ | |
4 | |
5 import 'dart:io'; | |
6 | |
7 import '../lib/HtmlToJson.dart' as htmlToJson; | |
8 import '../lib/JsonToHtml.dart' as jsonToHtml; | |
9 import '../../../pkg/args/lib/args.dart'; | |
10 | |
11 // Need this because ArgParser.getUsage doesn't show command invocation. | |
12 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.
| |
13 '<json path>\n[options] include:'; | |
14 final argParser = htmlJsonDocArgParser(); | |
15 | |
16 main() { | |
17 final args = new Options().arguments; | |
18 | |
19 if (args.isEmpty) { | |
20 printUsage('No arguments provided.'); | |
21 return; | |
22 } | |
23 | |
24 var htmlToJsonMode; | |
25 | |
26 final argResults = argParser.parse(args); | |
27 try { | |
28 htmlToJsonMode = argResults['mode'] == 'html-to-json'; | |
29 } 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.
| |
30 printUsage('Mode is a required option.'); | |
31 } | |
32 | |
33 var htmlPath = new Path.fromNative(argResults.rest[0]); | |
34 var jsonPath = new Path.fromNative(argResults.rest[1]); | |
35 | |
36 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.
| |
37 printUsage('Insufficient arguments.'); | |
38 return; | |
39 } | |
40 | |
41 var convertFuture; | |
42 if (htmlToJsonMode) { | |
43 convertFuture = htmlToJson.convert(htmlPath, jsonPath); | |
44 } else { | |
45 convertFuture = jsonToHtml.convert(htmlPath, jsonPath); | |
46 } | |
47 | |
48 convertFuture.then((anyErrors) { | |
49 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
| |
50 }); | |
51 } | |
52 | |
53 /// Prints the usage of the tool. [message] is printed if provided. | |
54 void printUsage([String message]) { | |
55 print(message); | |
56 print(USAGE); | |
57 print(argParser.getUsage()); | |
58 } | |
59 | |
60 ArgParser htmlJsonDocArgParser() { | |
61 final argParser = new ArgParser(); | |
62 | |
63 argParser.addOption('mode', abbr: 'm', | |
64 help: '(Required) Convert from HTML docs to JSON or vice versa.', | |
65 allowed: ['html-to-json', 'json-to-html'], allowedHelp: { | |
66 'html-to-json': 'Processes all HTML .dart files at given\n' | |
67 'location and outputs JSON.', | |
68 'json-to-html': 'Takes JSON file at location and inserts docs into\n' | |
69 '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
| |
70 ); | |
71 | |
72 return argParser; | |
73 } | |
OLD | NEW |