From acf3cd32905c76acc7e8b23513908b0b51a3ce63 Mon Sep 17 00:00:00 2001 From: Hemanth Krishna Date: Sat, 8 Jul 2023 00:17:52 +0530 Subject: [PATCH] feat(shorebird_cli): expose `--dart-define` directly in `shorebird run` (#693) Signed-off-by: Hemanth Krishna Co-authored-by: Felix Angelov --- .../shorebird_cli/lib/src/commands/run_command.dart | 11 +++++++++++ .../test/src/commands/run_command_test.dart | 4 ++++ 2 files changed, 15 insertions(+) diff --git a/packages/shorebird_cli/lib/src/commands/run_command.dart b/packages/shorebird_cli/lib/src/commands/run_command.dart index 716c33ed..b3f6c4a0 100644 --- a/packages/shorebird_cli/lib/src/commands/run_command.dart +++ b/packages/shorebird_cli/lib/src/commands/run_command.dart @@ -24,6 +24,15 @@ class RunCommand extends ShorebirdCommand abbr: 't', help: 'The main entrypoint file of the application.', ) + ..addMultiOption( + 'dart-define', + help: 'Additional key-value pairs that will be available as constants ' + '''from the String.fromEnvironment, bool.fromEnvironment, and int.fromEnvironment ''' + 'constructors.\n' + '''Multiple defines can be passed by repeating "--dart-define" multiple times.''', + splitCommas: false, + valueHelp: 'foo=bar', + ) ..addOption( 'flavor', help: 'The product flavor to use when building the app.', @@ -52,6 +61,7 @@ class RunCommand extends ShorebirdCommand final deviceId = results['device-id'] as String?; final flavor = results['flavor'] as String?; final target = results['target'] as String?; + final dartDefines = results['dart-define'] as List?; final flutter = await process.start( 'flutter', [ @@ -61,6 +71,7 @@ class RunCommand extends ShorebirdCommand if (deviceId != null) '--device-id=$deviceId', if (flavor != null) '--flavor=$flavor', if (target != null) '--target=$target', + if (dartDefines != null) ...dartDefines.map((e) => '--dart-define=$e'), ...results.rest ], runInShell: true, diff --git a/packages/shorebird_cli/test/src/commands/run_command_test.dart b/packages/shorebird_cli/test/src/commands/run_command_test.dart index b6828d58..bd491e23 100644 --- a/packages/shorebird_cli/test/src/commands/run_command_test.dart +++ b/packages/shorebird_cli/test/src/commands/run_command_test.dart @@ -179,9 +179,11 @@ void main() { const deviceId = 'test-device-id'; const flavor = 'development'; const target = './lib/main_development.dart'; + const dartDefines = ['FOO=BAR', 'BAZ=QUX']; when(() => argResults['device-id']).thenReturn(deviceId); when(() => argResults['flavor']).thenReturn(flavor); when(() => argResults['target']).thenReturn(target); + when(() => argResults['dart-define']).thenReturn(dartDefines); when(() => process.stdout).thenAnswer((_) => const Stream.empty()); when(() => process.stderr).thenAnswer((_) => const Stream.empty()); @@ -209,6 +211,8 @@ void main() { '--device-id=$deviceId', '--flavor=$flavor', '--target=$target', + '--dart-define=${dartDefines[0]}', + '--dart-define=${dartDefines[1]}', ]), );