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

Side by Side Diff: pkg/docgen/bin/docgen.dart

Issue 168743003: pkg/docgen: fix docs for --json flag, bin cleanup (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: rebase Created 6 years, 10 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 import 'package:path/path.dart' as path;
9 10
10 import '../lib/docgen.dart'; 11 import '../lib/docgen.dart';
11 import 'package:path/path.dart' as path;
12
13 List<String> excludedLibraries = [];
14
15 /**
16 * The files/directories that we're being asked to document.
17 */
18 List<String> _files;
19 12
20 /** 13 /**
21 * Analyzes Dart files and generates a representation of included libraries, 14 * Analyzes Dart files and generates a representation of included libraries,
22 * classes, and members. 15 * classes, and members.
23 */ 16 */
24 void main(List<String> arguments) { 17 void main(List<String> arguments) {
25 var options = _initArgParser().parse(arguments); 18 var options = _initArgParser().parse(arguments);
26 _files = options.rest.map(path.normalize).toList(); 19 var files = options.rest.map(path.normalize).toList();
27 if (_files.isEmpty) _printHelpAndExit(); 20 if (files.isEmpty) _printHelpAndExit();
28 var startPage = options['start-page']; 21 var startPage = options['start-page'];
29 if (_singlePackage(_files) && startPage == null) { 22 if (_singlePackage(files) && startPage == null) {
30 startPage = _defaultStartPage; 23 startPage = _getDefaultStartPage(files);
31 print("Using default options for documenting a single package: " 24 print("Using default options for documenting a single package: "
32 "--start-page=$startPage"); 25 "--start-page=$startPage");
33 } 26 }
34 var includeSdk = options['parse-sdk'] || options['include-sdk']; 27 var includeSdk = options['parse-sdk'] || options['include-sdk'];
35 var scriptDir = path.dirname(Platform.script.toFilePath()); 28 var scriptDir = path.dirname(Platform.script.toFilePath());
36 var introduction = includeSdk ? '' : options['introduction']; 29 var introduction = includeSdk ? '' : options['introduction'];
37 30
38 var pubScript = options['sdk'] != null ? 31 var pubScript = options['sdk'] != null ?
39 path.join(options['sdk'], 'bin', 'pub') : 'pub'; 32 path.join(options['sdk'], 'bin', 'pub') : 'pub';
40 33
41 var dartBinary = options['sdk'] != null ? 34 var dartBinary = options['sdk'] != null ?
42 path.join(options['sdk'], 'bin', 'dart') : 'dart'; 35 path.join(options['sdk'], 'bin', 'dart') : 'dart';
43 36
44 docgen(_files, 37 var excludedLibraries = options[_OPTION_EXCLUDE_LIB];
Alan Knight 2014/02/18 18:51:54 This complicates main that much more and doesn't s
kevmoo 2014/02/18 19:36:06 The upside is eliminating global state, IMHO. It's
Emily Fortuna 2014/02/18 21:07:06 Generally removing global state is good, but I'd a
kevmoo 2014/02/18 21:08:28 Another point: this is the only spot where a globa
38 if(excludedLibraries == null) excludedLibraries = [];
39
40 docgen(files,
45 packageRoot: options['package-root'], 41 packageRoot: options['package-root'],
46 outputToYaml: !options['json'], 42 outputToYaml: !options['json'],
47 includePrivate: options['include-private'], 43 includePrivate: options['include-private'],
48 includeSdk: includeSdk, 44 includeSdk: includeSdk,
49 parseSdk: options['parse-sdk'], 45 parseSdk: options['parse-sdk'],
50 append: options['append'] && new Directory(options['out']).existsSync(), 46 append: options['append'] && new Directory(options['out']).existsSync(),
51 introFileName: introduction, 47 introFileName: introduction,
52 out: options['out'], 48 out: options['out'],
53 excludeLibraries: excludedLibraries, 49 excludeLibraries: excludedLibraries,
54 includeDependentPackages: options['include-dependent-packages'], 50 includeDependentPackages: options['include-dependent-packages'],
(...skipping 22 matching lines...) Expand all
77 if (files.length != 1) return false; 73 if (files.length != 1) return false;
78 var pubspec = new File(path.join(files.first, 'pubspec.yaml')); 74 var pubspec = new File(path.join(files.first, 'pubspec.yaml'));
79 if (!pubspec.existsSync()) return false; 75 if (!pubspec.existsSync()) return false;
80 return true; 76 return true;
81 } 77 }
82 78
83 /** 79 /**
84 * If we've specified just a package and no other command-line options, 80 * If we've specified just a package and no other command-line options,
85 * use the single package name as the start page. 81 * use the single package name as the start page.
86 */ 82 */
87 String get _defaultStartPage { 83 String _getDefaultStartPage(files) {
Alan Knight 2014/02/18 18:51:54 I don't like "get" as a prefix. How about defaultS
Emily Fortuna 2014/02/18 19:32:10 +1
kevmoo 2014/02/18 19:36:06 Done.
88 var pubspec = new File(path.join(_files.first, 'pubspec.yaml')); 84 var pubspec = new File(path.join(files.first, 'pubspec.yaml'));
89 if (!pubspec.existsSync()) return null; 85 if (!pubspec.existsSync()) return null;
90 return Library.packageNameFor(_files.first); 86 return Library.packageNameFor(files.first);
91 } 87 }
92 88
93 /** 89 /**
94 * Creates parser for docgen command line arguments. 90 * Creates parser for docgen command line arguments.
95 */ 91 */
96 ArgParser _initArgParser() { 92 ArgParser _initArgParser() {
97 var parser = new ArgParser(); 93 var parser = new ArgParser();
98 parser.addFlag('help', abbr: 'h', 94 parser.addFlag('help', abbr: 'h',
99 help: 'Prints help and usage information.', 95 help: 'Prints help and usage information.',
100 negatable: false, 96 negatable: false,
101 callback: (help) { 97 callback: (help) {
102 if (help) _printHelpAndExit(); 98 if (help) _printHelpAndExit();
103 }); 99 });
104 parser.addFlag('verbose', abbr: 'v', 100 parser.addFlag('verbose', abbr: 'v',
105 help: 'Output more logging information.', negatable: false, 101 help: 'Output more logging information.', negatable: false,
106 callback: (verbose) { 102 callback: (verbose) {
107 if (verbose) Logger.root.level = Level.FINEST; 103 if (verbose) Logger.root.level = Level.FINEST;
108 }); 104 });
109 parser.addFlag('json', abbr: 'j', 105 parser.addFlag('json', abbr: 'j',
110 help: 'Outputs to JSON. Files are outputted to YAML by default. ' 106 help: 'Outputs to JSON. If negated, files are outputted to YAML. '
Alan Knight 2014/02/18 18:51:54 If we're fixing this, how about fixing outputted.
kevmoo 2014/02/18 19:36:06 Done.
111 'If --append is used, it takes the file-format of the previous ' 107 'If --append is used, it takes the file-format of the previous '
112 'run stated in library_list.json ignoring the flag.', 108 'run stated in library_list.json, ignoring the flag.',
113 negatable: true, defaultsTo: true); 109 negatable: true, defaultsTo: true);
114 parser.addFlag('include-private', 110 parser.addFlag('include-private',
115 help: 'Flag to include private declarations.', negatable: false); 111 help: 'Flag to include private declarations.', negatable: false);
116 parser.addFlag('include-sdk', 112 parser.addFlag('include-sdk',
117 help: 'Flag to parse SDK Library files.', 113 help: 'Flag to parse SDK Library files.',
118 defaultsTo: true, 114 defaultsTo: true,
119 negatable: true); 115 negatable: true);
120 parser.addFlag('parse-sdk', 116 parser.addFlag('parse-sdk',
121 help: 'Parses the SDK libraries only.', 117 help: 'Parses the SDK libraries only.',
122 defaultsTo: false, negatable: false); 118 defaultsTo: false, negatable: false);
(...skipping 10 matching lines...) Expand all
133 'and start a simple server', 129 'and start a simple server',
134 defaultsTo: false, negatable: false); 130 defaultsTo: false, negatable: false);
135 parser.addFlag('no-docs', help: 'Do not generate any new documentation', 131 parser.addFlag('no-docs', help: 'Do not generate any new documentation',
136 defaultsTo: false, negatable: false); 132 defaultsTo: false, negatable: false);
137 parser.addOption('introduction', 133 parser.addOption('introduction',
138 help: 'Adds the provided markdown text file as the introduction' 134 help: 'Adds the provided markdown text file as the introduction'
139 ' for the generated documentation.', defaultsTo: ''); 135 ' for the generated documentation.', defaultsTo: '');
140 parser.addOption('out', 136 parser.addOption('out',
141 help: 'The name of the output directory.', 137 help: 'The name of the output directory.',
142 defaultsTo: 'docs'); 138 defaultsTo: 'docs');
143 parser.addOption('exclude-lib', 139 parser.addOption(_OPTION_EXCLUDE_LIB,
Alan Knight 2014/02/18 18:51:54 If we're putting these in constants it should be a
Emily Fortuna 2014/02/18 19:32:10 +1
kevmoo 2014/02/18 19:36:06 Done.
144 help: 'Exclude the library by this name from the documentation', 140 help: 'Exclude the library by this name from the documentation',
145 allowMultiple: true, 141 allowMultiple: true);
146 callback: (libs) => excludedLibraries.addAll(libs));
147 parser.addFlag('include-dependent-packages', 142 parser.addFlag('include-dependent-packages',
148 help: 'Assumes we are documenting a single package and are running ' 143 help: 'Assumes we are documenting a single package and are running '
149 'in the directory with its pubspec. Includes documentation for all ' 144 'in the directory with its pubspec. Includes documentation for all '
150 'of its dependent packages.', 145 'of its dependent packages.',
151 defaultsTo: true, negatable: true); 146 defaultsTo: true, negatable: true);
152 parser.addOption('sdk', 147 parser.addOption('sdk',
153 help: 'SDK directory', 148 help: 'SDK directory',
154 defaultsTo: null); 149 defaultsTo: null);
155 parser.addOption('start-page', 150 parser.addOption('start-page',
156 help: 'By default the viewer will start at the SDK introduction page.' 151 help: 'By default the viewer will start at the SDK introduction page. '
157 'To start at some other page, e.g. for a package, provide the name ' 152 'To start at some other page, e.g. for a package, provide the name '
158 'of the package in this argument, e.g. --start-page=intl will make ' 153 'of the package in this argument, e.g. --start-page=intl will make '
159 'the start page of the viewer be the intl package.', 154 'the start page of the viewer be the intl package.',
160 defaultsTo: null); 155 defaultsTo: null);
161 156
162 return parser; 157 return parser;
163 } 158 }
159
160 const _OPTION_EXCLUDE_LIB = 'exclude-lib';
Emily Fortuna 2014/02/18 19:32:10 put constants up at top, please
161
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698