Skip to content
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
9 changes: 8 additions & 1 deletion lib/src/command_runner.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:args/args.dart';
import 'package:args/command_runner.dart';
import 'package:cli_completion/cli_completion.dart';
import 'package:mason/mason.dart' hide packageVersion;
import 'package:pub_updater/pub_updater.dart';
import 'package:usage/usage_io.dart';
Expand All @@ -18,7 +19,7 @@ const packageName = 'very_good_cli';
/// {@template very_good_command_runner}
/// A [CommandRunner] for the Very Good CLI.
/// {@endtemplate}
class VeryGoodCommandRunner extends CommandRunner<int> {
class VeryGoodCommandRunner extends CompletionCommandRunner<int> {
/// {@macro very_good_command_runner}
VeryGoodCommandRunner({
Analytics? analytics,
Expand Down Expand Up @@ -85,6 +86,7 @@ class VeryGoodCommandRunner extends CommandRunner<int> {
normalizedResponse == 'y' || normalizedResponse == 'yes';
}
final _argResults = parse(args);

if (_argResults['verbose'] == true) {
_logger.level = Level.verbose;
}
Expand All @@ -107,6 +109,11 @@ class VeryGoodCommandRunner extends CommandRunner<int> {

@override
Future<int?> runCommand(ArgResults topLevelResults) async {
if (topLevelResults.command?.name == 'completion') {
await super.runCommand(topLevelResults);
return ExitCode.success.code;
}

_logger
..detail('Argument information:')
..detail(' Top level options:');
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ environment:

dependencies:
args: ^2.1.0
cli_completion: 0.1.0
glob: ^2.0.2
lcov_parser: ^0.1.2
mason: ">=0.1.0-dev.39 <0.1.0-dev.40"
Expand Down
12 changes: 12 additions & 0 deletions test/src/command_runner_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,18 @@ void main() {
expect(result, equals(ExitCode.success.code));
});

test('handles completion command', () async {
final result = await commandRunner.run(['completion']);
verifyNever(() => logger.info(any()));
verifyNever(() => logger.err(any()));
verifyNever(() => logger.warn(any()));
verifyNever(() => logger.write(any()));
verifyNever(() => logger.success(any()));
verifyNever(() => logger.detail(any()));

expect(result, equals(ExitCode.success.code));
});

group('--help', () {
test('outputs usage', () async {
final result = await commandRunner.run(['--help']);
Expand Down