feat(shorebird_cli): add shorebird flutter config command (#2984)

This commit is contained in:
Felix Angelov
2025-03-17 14:55:21 -05:00
committed by GitHub
parent 6349471a0c
commit e3290d1f2f
6 changed files with 85 additions and 0 deletions
@@ -0,0 +1 @@
export '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<int> run() => process.stream('flutter', ['config', ...results.rest]);
}
@@ -1,2 +1,3 @@
export 'config/config.dart';
export 'flutter_command.dart';
export 'versions/versions.dart';
@@ -9,6 +9,7 @@ class FlutterCommand extends ShorebirdCommand {
/// {@macro flutter_command}
FlutterCommand() {
addSubcommand(FlutterVersionsCommand());
addSubcommand(FlutterConfigCommand());
}
@override
@@ -44,3 +44,11 @@ abstract class ShorebirdCommand extends Command<int> {
/// [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();
}
@@ -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>(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);
});
});
}