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

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

Issue 158833005: Use reasonable defaults for docgen if invoked on a single package (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Simplified 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 | pkg/docgen/lib/docgen.dart » ('j') | 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 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 * The files/directories that we're being asked to document.
17 */
18 List<String> _files;
19
20 /**
16 * Analyzes Dart files and generates a representation of included libraries, 21 * Analyzes Dart files and generates a representation of included libraries,
17 * classes, and members. 22 * classes, and members.
18 */ 23 */
19 void main(List<String> arguments) { 24 void main(List<String> arguments) {
20 var results = _initArgParser().parse(arguments); 25 var options = _initArgParser().parse(arguments);
26 _files = options.rest.map(path.normalize).toList();
27 if (_files.isEmpty) _printHelpAndExit();
28 var startPage = options['start-page'];
29 if (_singlePackage(_files) && startPage == null) {
30 startPage = _defaultStartPage;
31 print("Using default options for documenting a single package: "
32 "--start-page=$startPage");
33 }
34 var includeSdk = options['parse-sdk'] || options['include-sdk'];
35 var scriptDir = path.dirname(Platform.script.toFilePath());
36 var introduction = includeSdk ? '' : options['introduction'];
21 37
22 var includeSdk = results['parse-sdk'] || results['include-sdk']; 38 docgen(_files,
23 var scriptDir = path.dirname(Platform.script.toFilePath()); 39 packageRoot: options['package-root'],
24 var introduction = includeSdk ? '' : results['introduction']; 40 outputToYaml: !options['json'],
25 var files = results.rest.map(path.normalize).toList(); 41 includePrivate: options['include-private'],
26 if (files.isEmpty) _printHelpAndExit();
27 docgen(files,
28 packageRoot: results['package-root'],
29 outputToYaml: !results['json'],
30 includePrivate: results['include-private'],
31 includeSdk: includeSdk, 42 includeSdk: includeSdk,
32 parseSdk: results['parse-sdk'], 43 parseSdk: options['parse-sdk'],
33 append: results['append'] && new Directory(results['out']).existsSync(), 44 append: options['append'] && new Directory(options['out']).existsSync(),
34 introFileName: introduction, 45 introFileName: introduction,
35 out: results['out'], 46 out: options['out'],
36 excludeLibraries: excludedLibraries, 47 excludeLibraries: excludedLibraries,
37 includeDependentPackages: results['include-dependent-packages'], 48 includeDependentPackages: options['include-dependent-packages'],
38 serve: results['serve'], 49 serve: options['serve'],
39 noDocs: results['no-docs'], 50 noDocs: options['no-docs'],
40 startPage: results['startPage']); 51 startPage: startPage);
41 } 52 }
42 53
43 /** 54 /**
44 * Print help if we are passed the help option or invalid arguments. 55 * Print help if we are passed the help option or invalid arguments.
45 */ 56 */
46 void _printHelpAndExit() { 57 void _printHelpAndExit() {
47 print(_initArgParser().getUsage()); 58 print(_initArgParser().getUsage());
48 print('Usage: dart docgen.dart [OPTIONS] fooDir/barFile'); 59 print('Usage: dart docgen.dart [OPTIONS] fooDir/barFile');
49 exit(0); 60 exit(0);
50 } 61 }
51 62
52 /** 63 /**
64 * If the user seems to have given us a single package to document, use some
65 * reasonable arguments for what they probably meant.
66 */
67 bool _singlePackage(List files) {
68 if (files.length != 1) return false;
69 var pubspec = new File(path.join(files.first, 'pubspec.yaml'));
70 if (!pubspec.existsSync()) return false;
71 return true;
72 }
73
74 /**
75 * If we've specified just a package and no other command-line options,
76 * use the single package name as the start page.
77 */
78 String get _defaultStartPage {
79 var pubspec = new File(path.join(_files.first, 'pubspec.yaml'));
80 if (!pubspec.existsSync()) return null;
81 return Library.packageNameFor(_files.first);
82 }
83
84 /**
53 * Creates parser for docgen command line arguments. 85 * Creates parser for docgen command line arguments.
54 */ 86 */
55 ArgParser _initArgParser() { 87 ArgParser _initArgParser() {
56 var parser = new ArgParser(); 88 var parser = new ArgParser();
57 parser.addFlag('help', abbr: 'h', 89 parser.addFlag('help', abbr: 'h',
58 help: 'Prints help and usage information.', 90 help: 'Prints help and usage information.',
59 negatable: false, 91 negatable: false,
60 callback: (help) { 92 callback: (help) {
61 if (help) _printHelpAndExit(); 93 if (help) _printHelpAndExit();
62 }); 94 });
63 parser.addFlag('verbose', abbr: 'v', 95 parser.addFlag('verbose', abbr: 'v',
64 help: 'Output more logging information.', negatable: false, 96 help: 'Output more logging information.', negatable: false,
65 callback: (verbose) { 97 callback: (verbose) {
66 if (verbose) Logger.root.level = Level.FINEST; 98 if (verbose) Logger.root.level = Level.FINEST;
67 }); 99 });
68 parser.addFlag('json', abbr: 'j', 100 parser.addFlag('json', abbr: 'j',
69 help: 'Outputs to JSON. Files are outputted to YAML by default. ' 101 help: 'Outputs to JSON. Files are outputted to YAML by default. '
70 'If --append is used, it takes the file-format of the previous ' 102 'If --append is used, it takes the file-format of the previous '
71 'run stated in library_list.json ignoring the flag.', 103 'run stated in library_list.json ignoring the flag.',
72 negatable: true); 104 negatable: true, defaultsTo: true);
73 parser.addFlag('include-private', 105 parser.addFlag('include-private',
74 help: 'Flag to include private declarations.', negatable: false); 106 help: 'Flag to include private declarations.', negatable: false);
75 parser.addFlag('include-sdk', 107 parser.addFlag('include-sdk',
76 help: 'Flag to parse SDK Library files.', negatable: false); 108 help: 'Flag to parse SDK Library files.',
109 defaultsTo: true,
110 negatable: true);
77 parser.addFlag('parse-sdk', 111 parser.addFlag('parse-sdk',
78 help: 'Parses the SDK libraries only.', 112 help: 'Parses the SDK libraries only.',
79 defaultsTo: false, negatable: false); 113 defaultsTo: false, negatable: false);
80 parser.addOption('package-root', 114 parser.addOption('package-root',
81 help: 'Sets the package root of the library being analyzed.'); 115 help: 'Sets the package root of the library being analyzed.');
82 parser.addFlag('append', 116 parser.addFlag('append',
83 help: 'Append to the docs folder, library_list.json and index.txt', 117 help: 'Append to the docs folder, library_list.json and index.txt',
84 defaultsTo: false, negatable: false); 118 defaultsTo: false, negatable: false);
85 parser.addFlag('serve', help: 'Clone the documentation viewer repo locally ' 119 parser.addFlag('serve', help: 'Clone the documentation viewer repo locally '
86 '(if not already present) and start a simple server', defaultsTo: false, 120 '(if not already present) and start a simple server', defaultsTo: false,
87 negatable: false); 121 negatable: false);
88 parser.addFlag('no-docs', help: 'Do not generate any new documentation', 122 parser.addFlag('no-docs', help: 'Do not generate any new documentation',
89 defaultsTo: false, negatable: false); 123 defaultsTo: false, negatable: false);
90 parser.addOption('introduction', 124 parser.addOption('introduction',
91 help: 'Adds the provided markdown text file as the introduction' 125 help: 'Adds the provided markdown text file as the introduction'
92 ' for the generated documentation.', defaultsTo: ''); 126 ' for the generated documentation.', defaultsTo: '');
93 parser.addOption('out', 127 parser.addOption('out',
94 help: 'The name of the output directory.', 128 help: 'The name of the output directory.',
95 defaultsTo: 'docs'); 129 defaultsTo: 'docs');
96 parser.addOption('exclude-lib', 130 parser.addOption('exclude-lib',
97 help: 'Exclude the library by this name from the documentation', 131 help: 'Exclude the library by this name from the documentation',
98 allowMultiple: true, 132 allowMultiple: true,
99 callback: (libs) => excludedLibraries.addAll(libs)); 133 callback: (libs) => excludedLibraries.addAll(libs));
100 parser.addFlag('include-dependent-packages', 134 parser.addFlag('include-dependent-packages',
101 help: 'Assumes we are documenting a single package and are running ' 135 help: 'Assumes we are documenting a single package and are running '
102 'in the directory with its pubspec. Includes documentation for all ' 136 'in the directory with its pubspec. Includes documentation for all '
103 'of its dependent packages.', 137 'of its dependent packages.',
104 defaultsTo: false, negatable: false); 138 defaultsTo: true, negatable: true);
105 parser.addOption('startPage', 139 parser.addOption('start-page',
106 help: 'By default the viewer will start at the SDK introduction page.' 140 help: 'By default the viewer will start at the SDK introduction page.'
107 'To start at some other page, e.g. for a package, provide the name ' 141 'To start at some other page, e.g. for a package, provide the name '
108 'of the package in this argument, e.g. --startPage=intl will make ' 142 'of the package in this argument, e.g. --start-page=intl will make '
109 'the start page of the viewer be the intl package.', 143 'the start page of the viewer be the intl package.',
110 defaultsTo: null); 144 defaultsTo: null);
111 145
112 return parser; 146 return parser;
113 } 147 }
OLDNEW
« no previous file with comments | « no previous file | pkg/docgen/lib/docgen.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698