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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/docgen/bin/docgen.dart
diff --git a/pkg/docgen/bin/docgen.dart b/pkg/docgen/bin/docgen.dart
index 2a116de5b1bec5557663576bbb3959b1757c1734..db9e15d2c46d55e0b8cd4dcf2466808b8fc95473 100644
--- a/pkg/docgen/bin/docgen.dart
+++ b/pkg/docgen/bin/docgen.dart
@@ -12,17 +12,21 @@ import 'package:path/path.dart' as path;
List<String> excludedLibraries = [];
+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
+
/**
* Analyzes Dart files and generates a representation of included libraries,
* classes, and members.
*/
void main(List<String> arguments) {
- var results = _initArgParser().parse(arguments);
+ var results = argParser.parse(arguments);
var includeSdk = results['parse-sdk'] || results['include-sdk'];
var scriptDir = path.dirname(Platform.script.toFilePath());
var introduction = includeSdk ? '' : results['introduction'];
- docgen(results.rest.map(path.normalize).toList(),
+ var files = results.rest.map(path.normalize).toList();
+ if (files.isEmpty) printHelpAndExit();
+ docgen(files,
packageRoot: results['package-root'],
outputToYaml: !results['json'],
includePrivate: results['include-private'],
@@ -36,6 +40,15 @@ void main(List<String> arguments) {
}
/**
+ * Print help if we are passed the help option or invalid arguments.
+ */
+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
+ print(argParser.getUsage());
+ print('Usage: dart docgen.dart [OPTIONS] fooDir/barFile');
+ exit(0);
+}
+
+/**
* Creates parser for docgen command line arguments.
*/
ArgParser _initArgParser() {
@@ -44,11 +57,7 @@ ArgParser _initArgParser() {
help: 'Prints help and usage information.',
negatable: false,
callback: (help) {
- if (help) {
- print(parser.getUsage());
- print('Usage: dart docgen.dart [OPTIONS] fooDir/barFile');
- exit(0);
- }
+ if (help) printHelpAndExit();
});
parser.addFlag('verbose', abbr: 'v',
help: 'Output more logging information.', negatable: false,
« 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