| 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 import 'package:path/path.dart' as path; | 11 import 'package:path/path.dart' as path; |
| 12 | 12 |
| 13 List<String> excludedLibraries = []; | 13 List<String> excludedLibraries = []; |
| 14 | 14 |
| 15 /** | 15 /** |
| 16 * Analyzes Dart files and generates a representation of included libraries, | 16 * Analyzes Dart files and generates a representation of included libraries, |
| 17 * classes, and members. | 17 * classes, and members. |
| 18 */ | 18 */ |
| 19 void main(List<String> arguments) { | 19 void main(List<String> arguments) { |
| 20 var results = _initArgParser().parse(arguments); | 20 var results = _initArgParser().parse(arguments); |
| 21 | 21 |
| 22 var includeSdk = results['parse-sdk'] || results['include-sdk']; | 22 var includeSdk = results['parse-sdk'] || results['include-sdk']; |
| 23 var scriptDir = path.dirname(Platform.script.toFilePath()); | 23 var scriptDir = path.dirname(Platform.script.toFilePath()); |
| 24 var introduction = includeSdk ? '' : results['introduction']; | 24 var introduction = includeSdk ? '' : results['introduction']; |
| 25 docgen(results.rest.map(path.normalize).toList(), | 25 var files = results.rest.map(path.normalize).toList(); |
| 26 if (files.isEmpty) _printHelpAndExit(); |
| 27 docgen(files, |
| 26 packageRoot: results['package-root'], | 28 packageRoot: results['package-root'], |
| 27 outputToYaml: !results['json'], | 29 outputToYaml: !results['json'], |
| 28 includePrivate: results['include-private'], | 30 includePrivate: results['include-private'], |
| 29 includeSdk: includeSdk, | 31 includeSdk: includeSdk, |
| 30 parseSdk: results['parse-sdk'], | 32 parseSdk: results['parse-sdk'], |
| 31 append: results['append'] && new Directory(results['out']).existsSync(), | 33 append: results['append'] && new Directory(results['out']).existsSync(), |
| 32 introFileName: introduction, | 34 introFileName: introduction, |
| 33 out: results['out'], | 35 out: results['out'], |
| 34 excludeLibraries: excludedLibraries, | 36 excludeLibraries: excludedLibraries, |
| 35 includeDependentPackages: results['include-dependent-packages']); | 37 includeDependentPackages: results['include-dependent-packages']); |
| 36 } | 38 } |
| 37 | 39 |
| 38 /** | 40 /** |
| 41 * Print help if we are passed the help option or invalid arguments. |
| 42 */ |
| 43 void _printHelpAndExit() { |
| 44 print(_initArgParser().getUsage()); |
| 45 print('Usage: dart docgen.dart [OPTIONS] fooDir/barFile'); |
| 46 exit(0); |
| 47 } |
| 48 |
| 49 /** |
| 39 * Creates parser for docgen command line arguments. | 50 * Creates parser for docgen command line arguments. |
| 40 */ | 51 */ |
| 41 ArgParser _initArgParser() { | 52 ArgParser _initArgParser() { |
| 42 var parser = new ArgParser(); | 53 var parser = new ArgParser(); |
| 43 parser.addFlag('help', abbr: 'h', | 54 parser.addFlag('help', abbr: 'h', |
| 44 help: 'Prints help and usage information.', | 55 help: 'Prints help and usage information.', |
| 45 negatable: false, | 56 negatable: false, |
| 46 callback: (help) { | 57 callback: (help) { |
| 47 if (help) { | 58 if (help) _printHelpAndExit(); |
| 48 print(parser.getUsage()); | |
| 49 print('Usage: dart docgen.dart [OPTIONS] fooDir/barFile'); | |
| 50 exit(0); | |
| 51 } | |
| 52 }); | 59 }); |
| 53 parser.addFlag('verbose', abbr: 'v', | 60 parser.addFlag('verbose', abbr: 'v', |
| 54 help: 'Output more logging information.', negatable: false, | 61 help: 'Output more logging information.', negatable: false, |
| 55 callback: (verbose) { | 62 callback: (verbose) { |
| 56 if (verbose) Logger.root.level = Level.FINEST; | 63 if (verbose) Logger.root.level = Level.FINEST; |
| 57 }); | 64 }); |
| 58 parser.addFlag('json', abbr: 'j', | 65 parser.addFlag('json', abbr: 'j', |
| 59 help: 'Outputs to JSON. Files are outputted to YAML by default. ' | 66 help: 'Outputs to JSON. Files are outputted to YAML by default. ' |
| 60 'If --append is used, it takes the file-format of the previous ' | 67 'If --append is used, it takes the file-format of the previous ' |
| 61 'run stated in library_list.json ignoring the flag.', | 68 'run stated in library_list.json ignoring the flag.', |
| (...skipping 20 matching lines...) Expand all Loading... |
| 82 help: 'Exclude the library by this name from the documentation', | 89 help: 'Exclude the library by this name from the documentation', |
| 83 allowMultiple: true, | 90 allowMultiple: true, |
| 84 callback: (libs) => excludedLibraries.addAll(libs)); | 91 callback: (libs) => excludedLibraries.addAll(libs)); |
| 85 parser.addFlag('include-dependent-packages', | 92 parser.addFlag('include-dependent-packages', |
| 86 help: 'Assumes we are documenting a single package and are running ' | 93 help: 'Assumes we are documenting a single package and are running ' |
| 87 'in the directory with its pubspec. Includes documentation for all ' | 94 'in the directory with its pubspec. Includes documentation for all ' |
| 88 'of its dependent packages.', | 95 'of its dependent packages.', |
| 89 defaultsTo: false, negatable: false); | 96 defaultsTo: false, negatable: false); |
| 90 return parser; | 97 return parser; |
| 91 } | 98 } |
| OLD | NEW |