Chromium Code Reviews| Index: pkg/docgen/bin/docgen_main.dart |
| diff --git a/pkg/docgen/bin/docgen_main.dart b/pkg/docgen/bin/docgen_main.dart |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..e38aedfd937e15acdcdd8f54f5f6dd02942fe40b |
| --- /dev/null |
| +++ b/pkg/docgen/bin/docgen_main.dart |
| @@ -0,0 +1,87 @@ |
| +import 'dart:io'; |
| +import 'package:docgen/docgen.dart'; |
| +import 'package:args/args.dart'; |
| +import 'package:compiler_unsupported/implementation/mirrors/dart2js_mirror.dart'; |
| +import '../lib/src/dart2js_mirrors.dart' as dart2js; |
| +import 'package:compiler_unsupported/implementation/mirrors/mirrors.dart'; |
| +import 'package:compiler_unsupported/implementation/mirrors/mirrors_util.dart'; |
| + |
| +/** |
| + * Analyzes Dart files and generate a representation of included libraries, |
|
Andrei Mouravski
2013/06/18 19:31:00
generates
janicejl
2013/06/18 21:52:34
Done.
|
| + * classes and members. |
|
Andrei Mouravski
2013/06/18 22:54:01
Please use the Oxford Comma, that is to say,
"lib
|
| + */ |
| +void main() { |
| + var results = createArgParser().parse(new Options().arguments); |
| + Docgen docgen = new Docgen(sdkRoot: new Path("../../../../../dart/dart-sdk"), |
|
Andrei Mouravski
2013/06/18 22:54:01
Why does Docgen need the sdkRoot?
|
| + argResults: results); |
| + |
| + var libraries = _listLibraries(results.rest); |
| + Path packageDir = libraries.last.directoryPath.append("packages"); |
| + |
| + var workingMirrors = dart2js.analyze(libraries, docgen.sdkRoot, |
|
Andrei Mouravski
2013/06/18 22:54:01
This work looks like it should be done in the cont
|
| + packageRoot: packageDir, |
| + options: ['--preserve-comments', '--categories=Client,Server']); |
| + |
| + workingMirrors.then((MirrorSystem mirrorSystem) { |
| + if (mirrorSystem.libraries.values.isEmpty) { |
| + throw new UnsupportedError("No Library Mirrors. "); |
| + } |
| + docgen.libraries = mirrorSystem.libraries.values; |
| + docgen.documentLibraries(); |
| + }); |
| +} |
| + |
| +/** |
| + * Returns a ArgParser with all the flags and options created. |
| + */ |
| +ArgParser createArgParser() { |
|
Andrei Mouravski
2013/06/18 19:31:00
How about initArgParser
janicejl
2013/06/18 21:52:34
Done.
|
| + var parser = new ArgParser(); |
| + parser.addFlag("help", abbr: "h", |
| + help: "Prints help and usage information", |
| + negatable: false, |
| + callback: (help) { |
| + if (help) print(parser.getUsage()); |
| + }); |
| + parser.addFlag("yaml", abbr: "y", |
| + help: "Outputs to YAML", |
| + defaultsTo: true, negatable: true); |
| + parser.addFlag("json", abbr: "j", |
| + help: "Outputs to JSON", |
| + defaultsTo: false, negatable: true); |
| + parser.addFlag("hide-private", |
| + help: "Hides private declarations" , |
| + defaultsTo: false, negatable: false); |
| + parser.addFlag("sdk", |
| + help: "Flag to parse SDK Library files", |
| + defaultsTo: true, negatable: true); |
| + |
| + return parser; |
| +} |
| + |
| +List<Path> _listLibraries(List<String> args) { |
| + if (args.length != 1) { |
| + throw new UnsupportedError("Usage: dart docgen.dart [OPTIONS] [FILE/DIR]"); |
|
Andrei Mouravski
2013/06/18 22:54:01
Make a string constant for this since you use it o
|
| + } |
| + var libraries = new List<Path>(); |
| + var type = FileSystemEntity.typeSync(args[0]); |
| + |
| + if (type == FileSystemEntityType.LINK) { |
| + throw new UnsupportedError("""File should not be a link. |
|
Andrei Mouravski
2013/06/18 22:54:01
Why are these """ literal strings?
|
| +Usage: dart docgen.dart [OPTIONS] [FILE/DIR]"""); |
| + } else if (type == FileSystemEntityType.NOT_FOUND) { |
| + throw new UnsupportedError("""File does not exist. |
| +Usage: dart docgen.dart [OPTIONS] [FILE/DIR]"""); |
| + } else if (type == FileSystemEntityType.FILE) { |
| + libraries.add(new Path(args[0])); |
| + } else if (type == FileSystemEntityType.DIRECTORY) { |
| + new Directory(args[0]).listSync(recursive: true, |
| + followLinks: true).forEach((file) { |
| + if (new Path(file.path).extension == "dart") { |
| + if (!file.path.contains("/packages/")) { |
| + libraries.add(new Path(file.path)); |
| + } |
| + } |
| + }); |
| + } |
| + return libraries; |
| +} |