From 2f9693c7ec782f94504c908dc7eecbab5b696e47 Mon Sep 17 00:00:00 2001 From: Seth Ladd Date: Wed, 17 Jun 2015 16:08:23 +0200 Subject: [PATCH 1/2] throw if user passes a command-line arg --- bin/dartdoc.dart | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/bin/dartdoc.dart b/bin/dartdoc.dart index 017e2c8ea7..c7dbdb7384 100644 --- a/bin/dartdoc.dart +++ b/bin/dartdoc.dart @@ -19,7 +19,7 @@ main(List arguments) async { var args = parser.parse(arguments); if (args['help']) { - _printUsageAndExit(parser); + _printHelp(parser); } if (args['version']) { @@ -78,6 +78,11 @@ main(List arguments) async { packageRootDir = new Directory(_resolveTildePath(args['package-root'])); } + if (args.rest.isNotEmpty) { + print('Error: detected unknown command-line argument(s)'); + _printUsageAndExit(parser, exitCode: 1); + } + PackageMeta packageMeta = sdkDocs ? new PackageMeta.fromSdk(sdkDir, sdkReadmePath: readme) : new PackageMeta.fromDir(inputDir); @@ -105,12 +110,16 @@ main(List arguments) async { } } -/// Print help if we are passed the help option or invalid arguments. -void _printUsageAndExit(ArgParser parser) { +/// Print help if we are passed the help option. +void _printHelp(ArgParser parser, {int exitCode: 0}) { print('Generate HTML documentation for Dart libraries.\n'); + _printUsageAndExit(parser, exitCode: exitCode); +} + +void _printUsageAndExit(ArgParser parser, {int exitCode: 0}) { print('Usage: dartdoc [OPTIONS]\n'); print(parser.usage); - exit(0); + exit(exitCode); } ArgParser _createArgsParser() { From 4dcb8018b5a2ff769da01ec24dac8a6d77e92048 Mon Sep 17 00:00:00 2001 From: Seth Ladd Date: Wed, 17 Jun 2015 16:23:02 +0200 Subject: [PATCH 2/2] print unknown args --- bin/dartdoc.dart | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/bin/dartdoc.dart b/bin/dartdoc.dart index c7dbdb7384..e509ea6966 100644 --- a/bin/dartdoc.dart +++ b/bin/dartdoc.dart @@ -29,7 +29,7 @@ main(List arguments) async { Directory sdkDir = cli_util.getSdkDir(arguments); if (sdkDir == null) { - print("Warning: unable to locate the Dart SDK. Please use the --dart-sdk " + print("Error: unable to locate the Dart SDK. Please use the --dart-sdk " "command line option or set the DART_SDK environment variable."); exit(1); } @@ -41,13 +41,13 @@ main(List arguments) async { var readme = args['sdk-readme']; if (readme != null && !(new File(readme).existsSync())) { - print("Warning: unable to locate the SDK description file at $readme."); + print("Error: unable to locate the SDK description file at $readme."); exit(1); } Directory inputDir = new Directory(args['input']); if (!inputDir.existsSync()) { - print("Warning: unable to locate the input directory at ${inputDir.path}."); + print("Error: unable to locate the input directory at ${inputDir.path}."); exit(1); } @@ -56,14 +56,12 @@ main(List arguments) async { String url = args['hosted-url']; String footerFilePath = _resolveTildePath(args['footer']); if (footerFilePath != null && !new File(footerFilePath).existsSync()) { - print( - "Warning: unable to locate the file with footer at ${footerFilePath}."); + print("Error: unable to locate the file with footer at ${footerFilePath}."); exit(1); } String headerFilePath = _resolveTildePath(args['header']); if (headerFilePath != null && !new File(headerFilePath).existsSync()) { - print( - "Warning: unable to locate the file with header at ${headerFilePath}."); + print("Error: unable to locate the file with header at ${headerFilePath}."); exit(1); } @@ -79,7 +77,8 @@ main(List arguments) async { } if (args.rest.isNotEmpty) { - print('Error: detected unknown command-line argument(s)'); + var unknownArgs = args.rest.join(' '); + print('Error: detected unknown command-line argument(s): $unknownArgs'); _printUsageAndExit(parser, exitCode: 1); }