| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | |
| 2 // for details. All rights reserved. Use of this source code is governed by a | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 /** | |
| 6 * TODO(amouravski): Document stuff here. | |
| 7 */ | |
| 8 | |
| 9 import 'dart:io'; | |
| 10 | |
| 11 import '../lib/html_to_json.dart' as html_to_json; | |
| 12 import '../lib/json_to_html.dart' as json_to_html; | |
| 13 import '../../../pkg/args/lib/args.dart'; | |
| 14 | |
| 15 // Need this because ArgParser.getUsage doesn't show command invocation. | |
| 16 const USAGE = 'Usage htmlJsonDoc [options] --mode=<mode> <HTML.dart directory> ' | |
| 17 '<json path>\n[options] include:'; | |
| 18 final argParser = new ArgParser(); | |
| 19 | |
| 20 main() { | |
| 21 final args = new Options().arguments; | |
| 22 | |
| 23 if (args.isEmpty) { | |
| 24 printUsage('No arguments provided.'); | |
| 25 return; | |
| 26 } | |
| 27 | |
| 28 var mode; | |
| 29 argParser.addOption('mode', abbr: 'm', | |
| 30 help: '(Required) Convert from HTML docs to JSON or vice versa.', | |
| 31 allowed: ['html-to-json', 'json-to-html'], allowedHelp: { | |
| 32 'html-to-json': 'Processes all HTML .dart files at given\n' | |
| 33 'location and outputs JSON.', | |
| 34 'json-to-html': 'Takes JSON file at location and inserts docs into\n' | |
| 35 'HTML .dart files.'}, | |
| 36 callback: (m) => mode = m | |
| 37 ); | |
| 38 | |
| 39 final argResults = argParser.parse(args); | |
| 40 | |
| 41 if (mode == null) { | |
| 42 printUsage('Mode is a required option.'); | |
| 43 return; | |
| 44 } else if (argResults.rest.length < 2) { | |
| 45 printUsage('Insufficient arguments.'); | |
| 46 return; | |
| 47 } | |
| 48 | |
| 49 var htmlPath = new Path(argResults.rest[0]); | |
| 50 var jsonPath = new Path(argResults.rest[1]); | |
| 51 | |
| 52 var convertFuture; | |
| 53 if (mode == 'html-to-json') { | |
| 54 convertFuture = html_to_json.convert(htmlPath, jsonPath); | |
| 55 } else { | |
| 56 convertFuture = json_to_html.convert(htmlPath, jsonPath); | |
| 57 } | |
| 58 | |
| 59 convertFuture.then((anyErrors) { | |
| 60 print('Completed ${anyErrors ? "with" : "without"} errors.'); | |
| 61 }); | |
| 62 } | |
| 63 | |
| 64 /// Prints the usage of the tool. [message] is printed if provided. | |
| 65 void printUsage([String message]) { | |
| 66 print(message); | |
| 67 print(USAGE); | |
| 68 print(argParser.getUsage()); | |
| 69 } | |
| OLD | NEW |