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

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

Issue 143403006: Print options when given no arguments instead of crashing (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: 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 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 ArgParser argParser = _initArgParser();
Emily Fortuna 2014/02/04 20:40:03 why move this out as a global variable? I'd be mo
Alan Knight 2014/02/04 20:48:07 It seemed wasteful to create one, throw it away, a
16
15 /** 17 /**
16 * Analyzes Dart files and generates a representation of included libraries, 18 * Analyzes Dart files and generates a representation of included libraries,
17 * classes, and members. 19 * classes, and members.
18 */ 20 */
19 void main(List<String> arguments) { 21 void main(List<String> arguments) {
20 var results = _initArgParser().parse(arguments); 22 var results = argParser.parse(arguments);
21 23
22 var includeSdk = results['parse-sdk'] || results['include-sdk']; 24 var includeSdk = results['parse-sdk'] || results['include-sdk'];
23 var scriptDir = path.dirname(Platform.script.toFilePath()); 25 var scriptDir = path.dirname(Platform.script.toFilePath());
24 var introduction = includeSdk ? '' : results['introduction']; 26 var introduction = includeSdk ? '' : results['introduction'];
25 docgen(results.rest.map(path.normalize).toList(), 27 var files = results.rest.map(path.normalize).toList();
28 if (files.isEmpty) printHelpAndExit();
29 docgen(files,
26 packageRoot: results['package-root'], 30 packageRoot: results['package-root'],
27 outputToYaml: !results['json'], 31 outputToYaml: !results['json'],
28 includePrivate: results['include-private'], 32 includePrivate: results['include-private'],
29 includeSdk: includeSdk, 33 includeSdk: includeSdk,
30 parseSdk: results['parse-sdk'], 34 parseSdk: results['parse-sdk'],
31 append: results['append'] && new Directory(results['out']).existsSync(), 35 append: results['append'] && new Directory(results['out']).existsSync(),
32 introFileName: introduction, 36 introFileName: introduction,
33 out: results['out'], 37 out: results['out'],
34 excludeLibraries: excludedLibraries, 38 excludeLibraries: excludedLibraries,
35 includeDependentPackages: results['include-dependent-packages']); 39 includeDependentPackages: results['include-dependent-packages']);
36 } 40 }
37 41
38 /** 42 /**
43 * Print help if we are passed the help option or invalid arguments.
44 */
45 void printHelpAndExit() {
Emily Fortuna 2014/02/04 20:40:03 should probably make this private, yes?
Alan Knight 2014/02/04 20:48:07 Sure. I don't really know under what circumstances
46 print(argParser.getUsage());
47 print('Usage: dart docgen.dart [OPTIONS] fooDir/barFile');
48 exit(0);
49 }
50
51 /**
39 * Creates parser for docgen command line arguments. 52 * Creates parser for docgen command line arguments.
40 */ 53 */
41 ArgParser _initArgParser() { 54 ArgParser _initArgParser() {
42 var parser = new ArgParser(); 55 var parser = new ArgParser();
43 parser.addFlag('help', abbr: 'h', 56 parser.addFlag('help', abbr: 'h',
44 help: 'Prints help and usage information.', 57 help: 'Prints help and usage information.',
45 negatable: false, 58 negatable: false,
46 callback: (help) { 59 callback: (help) {
47 if (help) { 60 if (help) printHelpAndExit();
48 print(parser.getUsage());
49 print('Usage: dart docgen.dart [OPTIONS] fooDir/barFile');
50 exit(0);
51 }
52 }); 61 });
53 parser.addFlag('verbose', abbr: 'v', 62 parser.addFlag('verbose', abbr: 'v',
54 help: 'Output more logging information.', negatable: false, 63 help: 'Output more logging information.', negatable: false,
55 callback: (verbose) { 64 callback: (verbose) {
56 if (verbose) Logger.root.level = Level.FINEST; 65 if (verbose) Logger.root.level = Level.FINEST;
57 }); 66 });
58 parser.addFlag('json', abbr: 'j', 67 parser.addFlag('json', abbr: 'j',
59 help: 'Outputs to JSON. Files are outputted to YAML by default. ' 68 help: 'Outputs to JSON. Files are outputted to YAML by default. '
60 'If --append is used, it takes the file-format of the previous ' 69 'If --append is used, it takes the file-format of the previous '
61 'run stated in library_list.json ignoring the flag.', 70 'run stated in library_list.json ignoring the flag.',
(...skipping 20 matching lines...) Expand all
82 help: 'Exclude the library by this name from the documentation', 91 help: 'Exclude the library by this name from the documentation',
83 allowMultiple: true, 92 allowMultiple: true,
84 callback: (libs) => excludedLibraries.addAll(libs)); 93 callback: (libs) => excludedLibraries.addAll(libs));
85 parser.addFlag('include-dependent-packages', 94 parser.addFlag('include-dependent-packages',
86 help: 'Assumes we are documenting a single package and are running ' 95 help: 'Assumes we are documenting a single package and are running '
87 'in the directory with its pubspec. Includes documentation for all ' 96 'in the directory with its pubspec. Includes documentation for all '
88 'of its dependent packages.', 97 'of its dependent packages.',
89 defaultsTo: false, negatable: false); 98 defaultsTo: false, negatable: false);
90 return parser; 99 return parser;
91 } 100 }
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