diff --git a/pkg/dartdev/lib/src/commands/pub.dart b/pkg/dartdev/lib/src/commands/pub.dart index acc8e398616..1b24c6567f5 100644 --- a/pkg/dartdev/lib/src/commands/pub.dart +++ b/pkg/dartdev/lib/src/commands/pub.dart @@ -15,6 +15,25 @@ class PubCommand extends DartdevCommand { final ArgParser argParser = ArgParser.allowAnything(); + /// Override [printUsage] for invocations of 'dart help pub' which won't + /// execute [run] below. Without this, the 'dart help pub' reports the + /// command pub with no commands or flags. + @override + void printUsage() { + final command = sdk.pub; + final args = ['help']; + + log.trace('$command ${args.first}'); + + // Call 'pub help' + // Process.runSync(..) is used since [printUsage] is not an async method, + // and we want to guarantee that the result (the help text for the console) + // is printed before command exits. + final result = Process.runSync(command, args); + stderr.write(result.stderr); + stdout.write(result.stdout); + } + @override FutureOr run() async { final command = sdk.pub; diff --git a/pkg/dartdev/test/commands/help_test.dart b/pkg/dartdev/test/commands/help_test.dart new file mode 100644 index 00000000000..0c16d3e4a10 --- /dev/null +++ b/pkg/dartdev/test/commands/help_test.dart @@ -0,0 +1,26 @@ +// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file +// 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 'package:test/test.dart'; + +import '../utils.dart'; + +void main() { + group('help', help); +} + +void help() { + TestProject p; + + tearDown(() => p?.dispose()); + + test('pub', () { + p = project(); + var result = p.runSync('help', ['pub']); + + var pubHelpResult = p.runSync('pub', ['help']); + expect(result.stdout, contains(pubHelpResult.stdout)); + expect(result.stderr, contains(pubHelpResult.stderr)); + }); +} diff --git a/pkg/dartdev/test/test_all.dart b/pkg/dartdev/test/test_all.dart index 552691c3a47..4b9ccaad86f 100644 --- a/pkg/dartdev/test/test_all.dart +++ b/pkg/dartdev/test/test_all.dart @@ -8,6 +8,7 @@ import 'commands/analyze_test.dart' as analyze; import 'commands/create_test.dart' as create; import 'commands/flag_test.dart' as flag; import 'commands/format_test.dart' as format; +import 'commands/help_test.dart' as help; import 'commands/migrate_test.dart' as migrate; import 'commands/pub_test.dart' as pub; import 'commands/test_test.dart' as test; @@ -16,11 +17,12 @@ import 'sdk_test.dart' as sdk; import 'utils_test.dart' as utils; main() { - group('dartdev', () { + group('dart', () { analyze.main(); create.main(); flag.main(); format.main(); + help.main(); migrate.main(); pub.main(); test.main();