Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(177)

Unified Diff: pkg/docgen/bin/docgen_main.dart

Issue 16948010: added Command Line Arguments, support for directories, hiding private data, not parsing the SDK, rem (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/docgen/bin/docgen.dart ('k') | pkg/docgen/example/test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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;
+}
« no previous file with comments | « pkg/docgen/bin/docgen.dart ('k') | pkg/docgen/example/test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698