Don't allow outdated taking arguments (#2872)

diff --git a/lib/src/command/outdated.dart b/lib/src/command/outdated.dart
index 2b69c4c..632ff6f 100644
--- a/lib/src/command/outdated.dart
+++ b/lib/src/command/outdated.dart
@@ -41,6 +41,9 @@
   /// when we are outputting machine-readable json.
   bool get _shouldShowSpinner => stdout.hasTerminal && !argResults['json'];
 
+  @override
+  bool get takesArguments => false;
+
   OutdatedCommand() {
     argParser.addFlag(
       'color',
diff --git a/lib/src/command_runner.dart b/lib/src/command_runner.dart
index f130f37..f1ecb4d 100644
--- a/lib/src/command_runner.dart
+++ b/lib/src/command_runner.dart
@@ -134,8 +134,13 @@
 
   @override
   Future<int> run(Iterable<String> args) async {
-    _argResults = parse(args);
-    return await runCommand(_argResults) ?? exit_codes.SUCCESS;
+    try {
+      _argResults = parse(args);
+      return await runCommand(_argResults) ?? exit_codes.SUCCESS;
+    } on UsageException catch (error) {
+      log.exception(error);
+      return exit_codes.USAGE;
+    }
   }
 
   @override
@@ -146,12 +151,7 @@
       log.message('Pub ${sdk.version}');
       return 0;
     }
-    try {
-      return await super.runCommand(topLevelResults);
-    } on UsageException catch (error) {
-      log.exception(error);
-      return exit_codes.USAGE;
-    }
+    return await super.runCommand(topLevelResults);
   }
 
   @override
diff --git a/test/outdated/goldens/bad_arguments.txt b/test/outdated/goldens/bad_arguments.txt
new file mode 100644
index 0000000..1c0f1a7
--- /dev/null
+++ b/test/outdated/goldens/bad_arguments.txt
@@ -0,0 +1,56 @@
+$ pub outdated random_argument
+[ERR] Command "outdated" does not take any arguments.
+[ERR] 
+[ERR] Usage: pub outdated [options]
+[ERR] -h, --help                         Print this usage information.
+[ERR]     --[no-]color                   Whether to color the output.
+[ERR]                                    Defaults to color when connected to a
+[ERR]                                    terminal, and no-color otherwise.
+[ERR]     --[no-]dependency-overrides    Show resolutions with `dependency_overrides`.
+[ERR]                                    (defaults to on)
+[ERR]     --[no-]dev-dependencies        Take dev dependencies into account.
+[ERR]                                    (defaults to on)
+[ERR]     --json                         Output the results using a json format.
+[ERR]     --mode=<PROPERTY>              Highlight versions with PROPERTY.
+[ERR]                                    Only packages currently missing that PROPERTY
+[ERR]                                    will be included unless --show-all.
+[ERR]                                    [outdated (default), null-safety]
+[ERR]     --[no-]prereleases             Include prereleases in latest version.
+[ERR]                                    (defaults to on in --mode=null-safety).
+[ERR]     --[no-]show-all                Include dependencies that are already
+[ERR]                                    fullfilling --mode.
+[ERR]     --[no-]transitive              Show transitive dependencies.
+[ERR]                                    (defaults to off in --mode=null-safety).
+[ERR] 
+[ERR] Run "pub help" to see global options.
+[ERR] See https://dart.dev/tools/pub/cmd/pub-outdated for detailed documentation.
+[Exit code] 64
+
+$ pub outdated --bad_flag
+[ERR] Could not find an option named "bad_flag".
+[ERR] 
+[ERR] Usage: pub outdated [options]
+[ERR] -h, --help                         Print this usage information.
+[ERR]     --[no-]color                   Whether to color the output.
+[ERR]                                    Defaults to color when connected to a
+[ERR]                                    terminal, and no-color otherwise.
+[ERR]     --[no-]dependency-overrides    Show resolutions with `dependency_overrides`.
+[ERR]                                    (defaults to on)
+[ERR]     --[no-]dev-dependencies        Take dev dependencies into account.
+[ERR]                                    (defaults to on)
+[ERR]     --json                         Output the results using a json format.
+[ERR]     --mode=<PROPERTY>              Highlight versions with PROPERTY.
+[ERR]                                    Only packages currently missing that PROPERTY
+[ERR]                                    will be included unless --show-all.
+[ERR]                                    [outdated (default), null-safety]
+[ERR]     --[no-]prereleases             Include prereleases in latest version.
+[ERR]                                    (defaults to on in --mode=null-safety).
+[ERR]     --[no-]show-all                Include dependencies that are already
+[ERR]                                    fullfilling --mode.
+[ERR]     --[no-]transitive              Show transitive dependencies.
+[ERR]                                    (defaults to off in --mode=null-safety).
+[ERR] 
+[ERR] Run "pub help" to see global options.
+[ERR] See https://dart.dev/tools/pub/cmd/pub-outdated for detailed documentation.
+[Exit code] 64
+
diff --git a/test/outdated/goldens/no_pubspec.txt b/test/outdated/goldens/no_pubspec.txt
new file mode 100644
index 0000000..85afd8b
--- /dev/null
+++ b/test/outdated/goldens/no_pubspec.txt
@@ -0,0 +1,4 @@
+$ pub outdated 
+[ERR] Could not find a file named "pubspec.yaml" in "$SANDBOX/myapp".
+[Exit code] 66
+
diff --git a/test/outdated/outdated_test.dart b/test/outdated/outdated_test.dart
index c355ae0..a3210ff 100644
--- a/test/outdated/outdated_test.dart
+++ b/test/outdated/outdated_test.dart
@@ -2,6 +2,8 @@
 // for details. All rights reserved. Use of this source code is governed by a
 // BSD-style license that can be found in the LICENSE file.
 
+import 'dart:io';
+
 import 'package:test/test.dart';
 import '../descriptor.dart' as d;
 import '../golden_file.dart';
@@ -9,14 +11,11 @@
 
 /// Runs `pub outdated [args]` and appends the output to [buffer].
 Future<void> runPubOutdated(List<String> args, StringBuffer buffer,
-    {Map<String, String> environment,
-    dynamic exitCode = 0,
-    dynamic stdErr = isEmpty}) async {
+    {Map<String, String> environment}) async {
   final process =
       await startPub(args: ['outdated', ...args], environment: environment);
-  await process.shouldExit(exitCode);
+  final exitCode = await process.exitCode;
 
-  expect(await process.stderr.rest.toList(), stdErr);
   buffer.writeln([
     '\$ pub outdated ${args.join(' ')}',
     ...await process.stdout.rest.where((line) {
@@ -25,6 +24,16 @@
       return !line.startsWith('Downloading ');
     }).toList(),
   ].join('\n'));
+  final stderrLines = await process.stderr.rest.toList();
+  for (final line in stderrLines) {
+    final sanitized = line
+        .replaceAll(d.sandbox, r'$SANDBOX')
+        .replaceAll(Platform.pathSeparator, '/');
+    buffer.writeln('[ERR] $sanitized');
+  }
+  if (exitCode != 0) {
+    buffer.writeln('[Exit code] $exitCode');
+  }
   buffer.write('\n');
 }
 
@@ -65,10 +74,12 @@
   test('no pubspec', () async {
     await d.dir(appPath, []).create();
     final buffer = StringBuffer();
-    await runPubOutdated([], buffer,
-        exitCode: isNot(0),
-        stdErr: contains(
-            startsWith('Could not find a file named "pubspec.yaml" in ')));
+    await runPubOutdated(
+      [],
+      buffer,
+    );
+    expectMatchesGoldenFile(
+        buffer.toString(), 'test/outdated/goldens/no_pubspec.txt');
   });
 
   test('no lockfile', () async {
@@ -455,4 +466,12 @@
       'PUB_ENVIRONMENT': 'flutter_cli:get',
     });
   });
+
+  test("doesn't allow arguments. Handles bad flags", () async {
+    final sb = StringBuffer();
+    await runPubOutdated(['random_argument'], sb);
+    await runPubOutdated(['--bad_flag'], sb);
+    expectMatchesGoldenFile(
+        sb.toString(), 'test/outdated/goldens/bad_arguments.txt');
+  });
 }