feat(shorebird_cli): expose --dart-define directly in shorebird run (#693)

Signed-off-by: Hemanth Krishna <hkpdev008@gmail.com>
Co-authored-by: Felix Angelov <felix@shorebird.dev>
This commit is contained in:
Hemanth Krishna
2023-07-08 00:17:52 +05:30
committed by GitHub
parent 859f392ec5
commit acf3cd3290
2 changed files with 15 additions and 0 deletions
@@ -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<String>?;
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,
@@ -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]}',
]),
);