diff --git a/example/bin/example_cli.dart b/example/bin/example_cli.dart index 1600f65..8250a50 100644 --- a/example/bin/example_cli.dart +++ b/example/bin/example_cli.dart @@ -13,8 +13,6 @@ Future main(List args) async { /// exited already. This is useful to prevent Future chains from proceeding /// after you've decided to exit. Future _flushThenExit(int status) { - return Future.wait([ - stdout.close(), - stderr.close(), - ]).then((_) => exit(status)); + return Future.wait([stdout.close(), stderr.close()]) + .then((_) => exit(status)); } diff --git a/example/lib/src/command_runner.dart b/example/lib/src/command_runner.dart index 9613f70..495a740 100644 --- a/example/lib/src/command_runner.dart +++ b/example/lib/src/command_runner.dart @@ -16,17 +16,12 @@ const description = 'Example for cli_completion'; /// {@endtemplate} class ExampleCommandRunner extends CompletionCommandRunner { /// {@macro example_command_runner} - ExampleCommandRunner({ - Logger? logger, - }) : _logger = logger ?? Logger(), - super(executableName, description) { + new({Logger? logger}) + : _logger = logger ?? Logger(), + super(executableName, description) { // Add root options and flags argParser - ..addFlag( - 'rootFlag', - abbr: 'f', - help: 'A flag: in the root command', - ) + ..addFlag('rootFlag', abbr: 'f', help: 'A flag: in the root command') ..addOption('rootOption'); // Add sub commands diff --git a/example/lib/src/commands/some_commmand.dart b/example/lib/src/commands/some_commmand.dart index adb2134..7c735a6 100644 --- a/example/lib/src/commands/some_commmand.dart +++ b/example/lib/src/commands/some_commmand.dart @@ -5,30 +5,19 @@ import 'package:mason_logger/mason_logger.dart'; /// receives all the common cases of option mapping: options, muilt-options, /// flags and whatnot class SomeCommand extends Command { - SomeCommand(this._logger) { + new(this._logger) { argParser ..addOption( 'discrete', abbr: 'd', help: 'A discrete option with "allowed" values (mandatory)', allowed: ['foo', 'bar', 'faa'], - aliases: [ - 'allowed', - 'defined-values', - ], - allowedHelp: { - 'foo': 'foo help', - 'bar': 'bar help', - 'faa': 'faa help', - }, + aliases: ['allowed', 'defined-values'], + allowedHelp: {'foo': 'foo help', 'bar': 'bar help', 'faa': 'faa help'}, mandatory: true, ) ..addSeparator('yay') - ..addOption( - 'hidden', - hide: true, - help: 'A hidden option', - ) + ..addOption('hidden', hide: true, help: 'A hidden option') ..addOption( 'continuous', // intentionally, this one does not have an abbr help: 'A continuous option: any value is allowed', @@ -62,16 +51,8 @@ class SomeCommand extends Command { abbr: 'n', help: 'An continuous option that can be passed multiple times', ) - ..addFlag( - 'hiddenflag', - hide: true, - help: 'A hidden flag', - ) - ..addFlag( - 'flag', - abbr: 'f', - aliases: ['itIsAFlag'], - ) + ..addFlag('hiddenflag', hide: true, help: 'A hidden flag') + ..addFlag('flag', abbr: 'f', aliases: ['itIsAFlag']) ..addFlag( 'inverseflag', abbr: 'i', @@ -95,10 +76,7 @@ class SomeCommand extends Command { String get name => 'some_command'; @override - List get aliases => [ - 'disguised:some_commmand', - 'melon', - ]; + List get aliases => ['disguised:some_commmand', 'melon']; @override Future run() async { diff --git a/example/lib/src/commands/some_other_commmand.dart b/example/lib/src/commands/some_other_commmand.dart index d95f026..3261d34 100644 --- a/example/lib/src/commands/some_other_commmand.dart +++ b/example/lib/src/commands/some_other_commmand.dart @@ -3,7 +3,7 @@ import 'package:mason_logger/mason_logger.dart'; /// A command that only has a sub command class SomeOtherCommand extends Command { - SomeOtherCommand(this._logger) { + new(this._logger) { addSubcommand(_SomeSubCommand(_logger)); } @@ -19,7 +19,7 @@ class SomeOtherCommand extends Command { /// A command under [SomeOtherCommand] that does not receive options and read /// the "rest" field from arg results class _SomeSubCommand extends Command { - _SomeSubCommand(this._logger) { + new(this._logger) { argParser.addFlag( 'flag', help: 'a flag just to show we are in the subcommand', diff --git a/example/pubspec.yaml b/example/pubspec.yaml index d6d51b9..d0c2f45 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -15,7 +15,7 @@ dependencies: dev_dependencies: mocktail: ^1.0.4 test: ^1.25.8 - very_good_analysis: ^10.3.0 + very_good_analysis: ^11.0.0 executables: example_cli: diff --git a/example/test/integration/completion_integration_test.dart b/example/test/integration/completion_integration_test.dart index dda1bc7..f72d06d 100644 --- a/example/test/integration/completion_integration_test.dart +++ b/example/test/integration/completion_integration_test.dart @@ -108,17 +108,11 @@ void main() { }); test('totally written option', () async { - await expectLater( - 'example_cli --rootflag', - suggests(noSuggestions), - ); + await expectLater('example_cli --rootflag', suggests(noSuggestions)); }); test('totally written option (abbr)', () async { - await expectLater( - 'example_cli -f', - suggests(noSuggestions), - ); + await expectLater('example_cli -f', suggests(noSuggestions)); }); }); @@ -147,9 +141,7 @@ void main() { test('completes only one sub command', () async { await expectLater( 'example_cli some_comm', - suggests({ - 'some_command': 'This is help for some_command', - }), + suggests({'some_command': 'This is help for some_command'}), ); }); }); @@ -158,9 +150,7 @@ void main() { test('completes sub commands aliases when typed', () async { await expectLater( 'example_cli mel', - suggests({ - 'melon': 'This is help for some_command', - }), + suggests({'melon': 'This is help for some_command'}), ); }); @@ -245,16 +235,12 @@ void main() { ); }); - test( - 'options in between', - () async { - await expectLater( - 'example_cli -f --rootOption yay some_command', - suggests(allOptionsInThisLevel), - ); - }, - tags: 'known-issues', - ); + test('options in between', () async { + await expectLater( + 'example_cli -f --rootOption yay some_command', + suggests(allOptionsInThisLevel), + ); + }, tags: 'known-issues'); test('lots of spaces in between', () async { await expectLater( @@ -266,10 +252,7 @@ void main() { group('empty (aliases)', () { test('shows same options for alias sub command', () async { - await expectLater( - 'example_cli melon', - suggests(allOptionsInThisLevel), - ); + await expectLater('example_cli melon', suggests(allOptionsInThisLevel)); }); test('shows same options for alias sub command 2', () async { @@ -391,21 +374,14 @@ void main() { test('suggest possible options', () async { await expectLater( 'example_cli some_command --discrete ', - suggests({ - 'foo': 'foo help', - 'bar': 'bar help', - 'faa': 'faa help', - }), + suggests({'foo': 'foo help', 'bar': 'bar help', 'faa': 'faa help'}), ); }); test('suggest matching options', () async { await expectLater( 'example_cli some_command --discrete f', - suggests({ - 'foo': 'foo help', - 'faa': 'faa help', - }), + suggests({'foo': 'foo help', 'faa': 'faa help'}), ); }); @@ -424,11 +400,7 @@ void main() { test('suggest matching options for alias option when typed', () async { await expectLater( 'example_cli some_command --allowed ', - suggests({ - 'foo': 'foo help', - 'bar': 'bar help', - 'faa': 'faa help', - }), + suggests({'foo': 'foo help', 'bar': 'bar help', 'faa': 'faa help'}), ); }); @@ -462,11 +434,7 @@ void main() { test('suggest possible options', () async { await expectLater( 'example_cli some_command -d ', - suggests({ - 'foo': 'foo help', - 'bar': 'bar help', - 'faa': 'faa help', - }), + suggests({'foo': 'foo help', 'bar': 'bar help', 'faa': 'faa help'}), ); }); @@ -484,20 +452,14 @@ void main() { test('suggest matching options', () async { await expectLater( 'example_cli some_command -d f', - suggests({ - 'foo': 'foo help', - 'faa': 'faa help', - }), + suggests({'foo': 'foo help', 'faa': 'faa help'}), ); }); test('suggest matching options in a joined form', () async { await expectLater( 'example_cli some_command -df', - suggests({ - '-dfoo': 'foo help', - '-dfaa': 'faa help', - }), + suggests({'-dfoo': 'foo help', '-dfaa': 'faa help'}), ); }); }); @@ -626,16 +588,12 @@ void main() { ); }); - test( - 'include option after it is specified (abbr joined)', - () async { - await expectLater( - 'example_cli some_command -nyeahoo ', - suggests(allOptionsInThisLevel), - ); - }, - tags: 'known-issues', - ); + test('include option after it is specified (abbr joined)', () async { + await expectLater( + 'example_cli some_command -nyeahoo ', + suggests(allOptionsInThisLevel), + ); + }, tags: 'known-issues'); test( 'include discrete multi option value after it is specified', @@ -672,9 +630,7 @@ void main() { test('partially written sub command', () async { await expectLater( 'example_cli some_other_command sub', - suggests({ - 'subcommand': 'A sub command of some_other_command', - }), + suggests({'subcommand': 'A sub command of some_other_command'}), ); }); }); @@ -721,10 +677,7 @@ void main() { group('argument terminator bails', () { test('between commands', () async { - await expectLater( - 'example_cli -- some_command', - suggests(noSuggestions), - ); + await expectLater('example_cli -- some_command', suggests(noSuggestions)); }); test('after commands', () async { diff --git a/example/test/integration/utils.dart b/example/test/integration/utils.dart index c2a3c28..b45f80a 100644 --- a/example/test/integration/utils.dart +++ b/example/test/integration/utils.dart @@ -5,23 +5,18 @@ import 'package:mocktail/mocktail.dart'; import 'package:test/test.dart'; -class MockStdout extends Mock implements Stdout {} +class MockStdout extends Mock implements Stdout; Matcher suggests(Map suggestions, {int? whenCursorIsAt}) => - CliCompletionMatcher( - suggestions, - cursorIndex: whenCursorIsAt, - ); + CliCompletionMatcher(suggestions, cursorIndex: whenCursorIsAt); class CliCompletionMatcher extends CustomMatcher { - CliCompletionMatcher( - Map suggestions, { - this.cursorIndex, - }) : super( - 'Completes with the expected suggestions', - 'suggestions', - completion(suggestions), - ); + new(Map suggestions, {this.cursorIndex}) + : super( + 'Completes with the expected suggestions', + 'suggestions', + completion(suggestions), + ); final int? cursorIndex; @@ -47,11 +42,7 @@ Map prepareEnvForLineInput(String line, {int? cursorIndex}) { } return value; }); - return { - 'COMP_LINE': line, - 'COMP_POINT': '$cpoint', - 'COMP_CWORD': '$cword', - }; + return {'COMP_LINE': line, 'COMP_POINT': '$cpoint', 'COMP_CWORD': '$cword'}; } Future> runCompletionCommand( @@ -74,17 +65,14 @@ Future> runCompletionCommand( map[res.first] = description; }); - await IOOverrides.runZoned( - stdout: () => stdout, - () async { - final commandRunner = ExampleCommandRunner() - ..environmentOverride = { - 'SHELL': '/foo/bar/zsh', - ...prepareEnvForLineInput(line, cursorIndex: cursorIndex), - }; - await commandRunner.run(['completion']); - }, - ); + await IOOverrides.runZoned(stdout: () => stdout, () async { + final commandRunner = ExampleCommandRunner() + ..environmentOverride = { + 'SHELL': '/foo/bar/zsh', + ...prepareEnvForLineInput(line, cursorIndex: cursorIndex), + }; + await commandRunner.run(['completion']); + }); return map; } diff --git a/example/test/src/command_runner_test.dart b/example/test/src/command_runner_test.dart index b10976b..cc4a1f3 100644 --- a/example/test/src/command_runner_test.dart +++ b/example/test/src/command_runner_test.dart @@ -4,7 +4,7 @@ import 'package:mason_logger/mason_logger.dart'; import 'package:mocktail/mocktail.dart'; import 'package:test/test.dart'; -class MockLogger extends Mock implements Logger {} +class MockLogger extends Mock implements Logger; void main() { group('ExampleCommandRunner', () { @@ -14,18 +14,13 @@ void main() { setUp(() { logger = MockLogger(); - commandRunner = ExampleCommandRunner( - logger: logger, - ); + commandRunner = ExampleCommandRunner(logger: logger); }); - test( - 'can be instantiated without an explicit logger instance', - () { - final commandRunner = ExampleCommandRunner(); - expect(commandRunner, isNotNull); - }, - ); + test('can be instantiated without an explicit logger instance', () { + final commandRunner = ExampleCommandRunner(); + expect(commandRunner, isNotNull); + }); test('handles FormatException', () async { const exception = FormatException('oops!'); @@ -61,9 +56,8 @@ void main() { test('does nothing', () async { final result = await commandRunner.run(['--rootFlag']); expect(result, equals(ExitCode.success.code)); - verify( - () => logger.info('You used the root flag, it does nothing :)'), - ).called(1); + verify(() => logger.info('You used the root flag, it does nothing :)')) + .called(1); }); }); @@ -71,9 +65,7 @@ void main() { test('usesLogger', () async { commandRunner.printUsage(); - final a = verify( - () => logger.info(captureAny()), - ).captured; + final a = verify(() => logger.info(captureAny())).captured; expect(a.first, ''' Example for cli_completion diff --git a/example/test/src/commands/some_command_test.dart b/example/test/src/commands/some_command_test.dart index 2233ab0..1843d17 100644 --- a/example/test/src/commands/some_command_test.dart +++ b/example/test/src/commands/some_command_test.dart @@ -3,7 +3,7 @@ import 'package:mason_logger/mason_logger.dart'; import 'package:mocktail/mocktail.dart'; import 'package:test/test.dart'; -class MockLogger extends Mock implements Logger {} +class MockLogger extends Mock implements Logger; void main() { group('SomeCommand', () { @@ -13,9 +13,7 @@ void main() { setUp(() { logger = MockLogger(); - commandRunner = ExampleCommandRunner( - logger: logger, - ); + commandRunner = ExampleCommandRunner(logger: logger); }); test('list passed options', () async { diff --git a/example/test/src/commands/some_other_command_test.dart b/example/test/src/commands/some_other_command_test.dart index e8c296f..c77013b 100644 --- a/example/test/src/commands/some_other_command_test.dart +++ b/example/test/src/commands/some_other_command_test.dart @@ -3,7 +3,7 @@ import 'package:mason_logger/mason_logger.dart'; import 'package:mocktail/mocktail.dart'; import 'package:test/test.dart'; -class MockLogger extends Mock implements Logger {} +class MockLogger extends Mock implements Logger; void main() { group('SomeOtherCommand', () { @@ -13,9 +13,7 @@ void main() { setUp(() { logger = MockLogger(); - commandRunner = ExampleCommandRunner( - logger: logger, - ); + commandRunner = ExampleCommandRunner(logger: logger); }); test('list passed options', () async { @@ -25,9 +23,8 @@ void main() { expect(exitCode, ExitCode.success.code); - verify( - () => logger.info('A sub command of some_other_command'), - ).called(1); + verify(() => logger.info('A sub command of some_other_command')) + .called(1); verify(() => logger.info(' - anything')).called(1); verify(() => logger.info(' - after')).called(1); verify(() => logger.info(' - command')).called(1);