From e3290d1f2feaf852f72d0b4625f3efe3139ac6e3 Mon Sep 17 00:00:00 2001 From: Felix Angelov Date: Mon, 17 Mar 2025 14:55:21 -0500 Subject: [PATCH] feat(shorebird_cli): add `shorebird flutter config` command (#2984) --- .../src/commands/flutter/config/config.dart | 1 + .../config/flutter_config_command.dart | 20 +++++++ .../lib/src/commands/flutter/flutter.dart | 1 + .../src/commands/flutter/flutter_command.dart | 1 + .../lib/src/shorebird_command.dart | 8 +++ .../config/flutter_config_command_test.dart | 54 +++++++++++++++++++ 6 files changed, 85 insertions(+) create mode 100644 packages/shorebird_cli/lib/src/commands/flutter/config/config.dart create mode 100644 packages/shorebird_cli/lib/src/commands/flutter/config/flutter_config_command.dart create mode 100644 packages/shorebird_cli/test/src/commands/flutter/config/flutter_config_command_test.dart diff --git a/packages/shorebird_cli/lib/src/commands/flutter/config/config.dart b/packages/shorebird_cli/lib/src/commands/flutter/config/config.dart new file mode 100644 index 00000000..0a7f8e91 --- /dev/null +++ b/packages/shorebird_cli/lib/src/commands/flutter/config/config.dart @@ -0,0 +1 @@ +export 'flutter_config_command.dart'; diff --git a/packages/shorebird_cli/lib/src/commands/flutter/config/flutter_config_command.dart b/packages/shorebird_cli/lib/src/commands/flutter/config/flutter_config_command.dart new file mode 100644 index 00000000..ef2cdfd5 --- /dev/null +++ b/packages/shorebird_cli/lib/src/commands/flutter/config/flutter_config_command.dart @@ -0,0 +1,20 @@ +import 'dart:async'; + +import 'package:shorebird_cli/src/shorebird_command.dart'; +import 'package:shorebird_cli/src/shorebird_process.dart'; + +/// {@template flutter_config_command} +/// `shorebird flutter config` +/// Manage your Shorebird Flutter Config. +/// {@endtemplate} +class FlutterConfigCommand extends ShorebirdProxyCommand { + @override + String get description => + 'Configure Flutter settings. This proxies to the underlying `flutter config` command.'; + + @override + String get name => 'config'; + + @override + FutureOr run() => process.stream('flutter', ['config', ...results.rest]); +} diff --git a/packages/shorebird_cli/lib/src/commands/flutter/flutter.dart b/packages/shorebird_cli/lib/src/commands/flutter/flutter.dart index 0b2035a1..93484319 100644 --- a/packages/shorebird_cli/lib/src/commands/flutter/flutter.dart +++ b/packages/shorebird_cli/lib/src/commands/flutter/flutter.dart @@ -1,2 +1,3 @@ +export 'config/config.dart'; export 'flutter_command.dart'; export 'versions/versions.dart'; diff --git a/packages/shorebird_cli/lib/src/commands/flutter/flutter_command.dart b/packages/shorebird_cli/lib/src/commands/flutter/flutter_command.dart index 3d1c9e75..4563ae65 100644 --- a/packages/shorebird_cli/lib/src/commands/flutter/flutter_command.dart +++ b/packages/shorebird_cli/lib/src/commands/flutter/flutter_command.dart @@ -9,6 +9,7 @@ class FlutterCommand extends ShorebirdCommand { /// {@macro flutter_command} FlutterCommand() { addSubcommand(FlutterVersionsCommand()); + addSubcommand(FlutterConfigCommand()); } @override diff --git a/packages/shorebird_cli/lib/src/shorebird_command.dart b/packages/shorebird_cli/lib/src/shorebird_command.dart index 6ffb481e..0aa05f04 100644 --- a/packages/shorebird_cli/lib/src/shorebird_command.dart +++ b/packages/shorebird_cli/lib/src/shorebird_command.dart @@ -44,3 +44,11 @@ abstract class ShorebirdCommand extends Command { /// [ArgResults] for the current command. ArgResults get results => testArgResults ?? argResults!; } + +/// {@template shorebird_proxy_command} +/// A command in the Shorebird CLI that proxies to an underlying process. +/// {@endtemplate} +abstract class ShorebirdProxyCommand extends ShorebirdCommand { + @override + ArgParser get argParser => ArgParser.allowAnything(); +} diff --git a/packages/shorebird_cli/test/src/commands/flutter/config/flutter_config_command_test.dart b/packages/shorebird_cli/test/src/commands/flutter/config/flutter_config_command_test.dart new file mode 100644 index 00000000..6d491792 --- /dev/null +++ b/packages/shorebird_cli/test/src/commands/flutter/config/flutter_config_command_test.dart @@ -0,0 +1,54 @@ +import 'package:args/args.dart'; +import 'package:mason_logger/mason_logger.dart'; +import 'package:mocktail/mocktail.dart'; +import 'package:scoped_deps/scoped_deps.dart'; +import 'package:shorebird_cli/src/commands/flutter/config/flutter_config_command.dart'; +import 'package:shorebird_cli/src/shorebird_process.dart'; +import 'package:test/test.dart'; + +import '../../../mocks.dart'; + +void main() { + group(FlutterConfigCommand, () { + late ShorebirdProcess process; + late ArgResults argResults; + late FlutterConfigCommand command; + + R runWithOverrides(R Function() body) { + return runScoped(body, values: {processRef.overrideWith(() => process)}); + } + + setUp(() { + argResults = MockArgResults(); + process = MockShorebirdProcess(); + command = runWithOverrides(FlutterConfigCommand.new) + ..testArgResults = argResults; + }); + + test('has correct name and description', () { + expect(command.name, equals('config')); + expect( + command.description, + equals( + 'Configure Flutter settings. This proxies to the underlying `flutter config` command.', + ), + ); + }); + + test('runs the `flutter config` command', () async { + final exitCode = ExitCode.success.code; + final args = ['--jdk-dir', '/path/to/jdk']; + when(() => argResults.rest).thenReturn(args); + when( + () => process.stream('flutter', ['config', ...args]), + ).thenAnswer((_) async => exitCode); + + await expectLater( + runWithOverrides(command.run), + completion(equals(exitCode)), + ); + + verify(() => process.stream('flutter', ['config', ...args])).called(1); + }); + }); +}