Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 import 'dart:io'; | 5 import 'dart:io'; |
| 6 | 6 |
| 7 import 'package:args/args.dart'; | 7 import 'package:args/args.dart'; |
| 8 import 'package:logging/logging.dart'; | 8 import 'package:logging/logging.dart'; |
| 9 | 9 |
| 10 import '../lib/docgen.dart'; | 10 import '../lib/docgen.dart'; |
| 11 | 11 |
| 12 /** | 12 /** |
| 13 * Analyzes Dart files and generates a representation of included libraries, | 13 * Analyzes Dart files and generates a representation of included libraries, |
| 14 * classes, and members. | 14 * classes, and members. |
| 15 */ | 15 */ |
| 16 void main() { | 16 void main() { |
| 17 logger.onRecord.listen((record) => print(record.message)); | 17 logger.onRecord.listen((record) => print(record.message)); |
| 18 var results = initArgParser().parse(new Options().arguments); | 18 var results = initArgParser().parse(new Options().arguments); |
| 19 if (results['help']) return; | 19 var outputToYaml = results['yaml'] || results['output-format'] == 'yaml'; |
|
Andrei Mouravski
2013/07/02 02:21:44
Newline.
janicejl
2013/07/02 17:18:51
Done.
| |
| 20 docgen(results); | 20 var outputToJson = results['json'] || results['output-format'] == 'json'; |
| 21 if (outputToYaml && outputToJson) { | |
| 22 throw new ArgumentError('Cannot have contradictory output flags.'); | |
| 23 } | |
| 24 outputToYaml = outputToYaml || !outputToJson; | |
| 25 docgen(results.rest, | |
|
Andrei Mouravski
2013/07/02 02:21:44
Newline.
janicejl
2013/07/02 17:18:51
Done.
| |
| 26 packageRoot: results['package-root'], outputToYaml: outputToYaml, | |
|
Andrei Mouravski
2013/07/02 02:21:44
Move outputToYaml:... to next line.
janicejl
2013/07/02 17:18:51
Done.
| |
| 27 includePrivate: results['include-private'], | |
| 28 includeSdk: results['parse-sdk'] || results['include-sdk'], | |
| 29 parseSdk: results['parse-sdk']); | |
| 21 } | 30 } |
| 22 | 31 |
| 23 /** | 32 /** |
| 24 * Creates parser for docgen command line arguments. | 33 * Creates parser for docgen command line arguments. |
| 25 */ | 34 */ |
| 26 ArgParser initArgParser() { | 35 ArgParser initArgParser() { |
| 27 var parser = new ArgParser(); | 36 var parser = new ArgParser(); |
| 28 parser.addFlag('help', abbr: 'h', | 37 parser.addFlag('help', abbr: 'h', |
| 29 help: 'Prints help and usage information.', | 38 help: 'Prints help and usage information.', |
| 30 negatable: false, | 39 negatable: false, |
| 31 callback: (help) { | 40 callback: (help) { |
| 32 if (help) { | 41 if (help) { |
| 33 logger.info(parser.getUsage()); | 42 logger.info(parser.getUsage()); |
| 34 logger.info(USAGE); | 43 logger.info(USAGE); |
| 44 exit(0); | |
| 35 } | 45 } |
| 36 }); | 46 }); |
| 37 parser.addFlag('verbose', abbr: 'v', | 47 parser.addFlag('verbose', abbr: 'v', |
| 38 help: 'Output more logging information.', negatable: false, | 48 help: 'Output more logging information.', negatable: false, |
| 39 callback: (verbose) { | 49 callback: (verbose) { |
| 40 if (verbose) Logger.root.level = Level.FINEST; | 50 if (verbose) Logger.root.level = Level.FINEST; |
| 41 }); | 51 }); |
| 42 parser.addOption('output-format', abbr: 'o', | 52 parser.addOption('output-format', abbr: 'o', |
| 43 help: 'Sets the output format.', | 53 help: 'Sets the output format.', |
| 44 allowed: ['yaml', 'json'], | 54 allowed: ['yaml', 'json'], |
| 45 allowedHelp: {'yaml' : 'Outputs to YAML. (Default)', | 55 allowedHelp: {'yaml' : 'Outputs to YAML. (Default)', |
| 46 'json' : 'Outputs to JSON.'}); | 56 'json' : 'Outputs to JSON.'}); |
| 47 parser.addFlag('yaml', abbr: 'y', | 57 parser.addFlag('yaml', abbr: 'y', |
| 48 help: 'Same as output-format=yaml.', negatable: false); | 58 help: 'Same as output-format=yaml.', negatable: false); |
| 49 parser.addFlag('json', abbr: 'j', | 59 parser.addFlag('json', abbr: 'j', |
| 50 help: 'Same as output-format=json.', negatable: false); | 60 help: 'Same as output-format=json.', negatable: false); |
| 51 parser.addFlag('include-private', | 61 parser.addFlag('include-private', |
| 52 help: 'Flag to include private declarations.', negatable: false); | 62 help: 'Flag to include private declarations.', negatable: false); |
| 53 parser.addFlag('include-sdk', | 63 parser.addFlag('include-sdk', |
| 54 help: 'Flag to parse SDK Library files.', negatable: false); | 64 help: 'Flag to parse SDK Library files.', negatable: false); |
| 55 parser.addFlag('parse-sdk', | 65 parser.addFlag('parse-sdk', |
| 56 help: 'Parses the SDK libraries only.', | 66 help: 'Parses the SDK libraries only.', |
| 57 defaultsTo: false, negatable: false); | 67 defaultsTo: false, negatable: false); |
| 58 parser.addOption('package-root', | 68 parser.addOption('package-root', |
| 59 help: "Sets the package root of the library being analyzed."); | 69 help: "Sets the package root of the library being analyzed."); |
| 60 | 70 |
| 61 return parser; | 71 return parser; |
| 62 } | 72 } |
| OLD | NEW |