diff --git a/lib/src/command/add.dart b/lib/src/command/add.dart index fda22503d..d74dd6c10 100644 --- a/lib/src/command/add.dart +++ b/lib/src/command/add.dart @@ -82,6 +82,8 @@ class AddCommand extends PubCommand { Future runProtected() async { if (argResults.rest.isEmpty) { usageException('Must specify a package to be added.'); + } else if (argResults.rest.length > 1) { + usageException('Takes only a single argument.'); } final packageInformation = _parsePackage(argResults.rest.first); diff --git a/test/add/common/add_test.dart b/test/add/common/add_test.dart index 5252978d0..c3c77391a 100644 --- a/test/add/common/add_test.dart +++ b/test/add/common/add_test.dart @@ -37,6 +37,30 @@ void main() { }); group('normally', () { + test('fails if extra arguments are passed', () async { + await servePackages((builder) { + builder.serve('foo', '1.2.2'); + }); + + await d.dir(appPath, [ + d.pubspec({'name': 'myapp'}) + ]).create(); + + await pubAdd( + args: ['foo', '^1.2.2'], + exitCode: exit_codes.USAGE, + error: contains('Takes only a single argument.')); + + await d.dir(appPath, [ + d.pubspec({ + 'name': 'myapp', + }), + d.nothing('.dart_tool/package_config.json'), + d.nothing('pubspec.lock'), + d.nothing('.packages'), + ]).validate(); + }); + test('adds a package from a pub server', () async { await servePackages((builder) => builder.serve('foo', '1.2.3'));