Skip to content

error for extra args, print red errors #42

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions webdev/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.2.1

- Exit with an error if unsupported arguments are passed to `build` command.

## 0.2.0

- Pass the arguments supporting `directory:port` for the `serve` command.
Expand Down
6 changes: 3 additions & 3 deletions webdev/bin/webdev.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@ Future main(List<String> args) async {
try {
exitCode = await run(args);
} on UsageException catch (e) {
print(yellow.wrap(e.message));
print(red.wrap(e.message));
print(' ');
print(e.usage);
exitCode = ExitCode.usage.code;
} on FileSystemException catch (e) {
print(yellow.wrap('$_boldApp could not run in the current directory.'));
print(red.wrap('$_boldApp could not run in the current directory.'));
print(e.message);
if (e.path != null) {
print(' ${e.path}');
}
exitCode = ExitCode.config.code;
} on PackageException catch (e) {
print(yellow.wrap('$_boldApp could not run for this project.'));
print(red.wrap('$_boldApp could not run for this project.'));
for (var detail in e.details) {
print(yellow.wrap(detail.error));
if (detail.description != null) {
Expand Down
13 changes: 12 additions & 1 deletion webdev/lib/src/command/build_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
// BSD-style license that can be found in the LICENSE file.

import 'dart:async';

import 'package:args/command_runner.dart';

import 'command_base.dart';

/// Command to execute pub run build_runner build.
Expand All @@ -16,5 +19,13 @@ class BuildCommand extends CommandBase {
final description = 'Run builders to build a package.';

@override
Future<int> run() => runCore('build');
Future<int> run() {
if (argResults.rest.isNotEmpty) {
throw new UsageException(
'Arguments were provided that are not supported: '
'"${argResults.rest.join(' ')}".',
argParser.usage);
}
return runCore('build');
}
}
2 changes: 1 addition & 1 deletion webdev/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: webdev
version: 0.2.0
version: 0.2.1-dev
author: Dart Team <misc@dartlang.org>
homepage: https://github.com/dart-lang/webdev
description: >-
Expand Down
9 changes: 9 additions & 0 deletions webdev/test/integration_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ void main() {
await process.shouldExit(64);
});

test('passing extra args to build fails with bad usage', () async {
var process = await runWebDev(['build', 'extra', 'args']);

await expectLater(process.stdout,
emits('Arguments were provided that are not supported: "extra args".'));

await process.shouldExit(64);
});

var invalidRanges = <String, List<String>>{
'build_runner': ['0.7.13+1', '0.9.0'],
'build_web_compilers': ['0.3.5', '0.4.0']
Expand Down