Skip to content

Commit

Permalink
Exit with an error if unsupported arguments are passed to build
Browse files Browse the repository at this point in the history
Fixes #41
  • Loading branch information
kevmoo committed Apr 21, 2018
1 parent 8696973 commit 7dc709f
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 deletions.
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
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

0 comments on commit 7dc709f

Please sign in to comment.