Unverified Commit 2b512781 authored by George Wright's avatar George Wright Committed by GitHub

Add a --dart-entrypoint-args flag to flutter run to pass through Dart...

Add a --dart-entrypoint-args flag to flutter run to pass through Dart entrypoint arguments on Flutter Desktop (#69607)
parent b8d21ad3
......@@ -115,7 +115,14 @@ abstract class RunCommandBase extends FlutterCommand with DeviceBasedDevelopment
help: 'Filters out all trace events except those that are specified in '
'this comma separated list of allowed prefixes.',
valueHelp: 'foo,bar',
);
)
..addMultiOption('dart-entrypoint-args',
abbr: 'a',
help: 'Pass a list of arguments to the Dart entrypoint at application '
'startup. By default this is main(List<String> args). Specify '
'this option multiple times each with one argument to pass '
'multiple arguments to the Dart entrypoint. Currently this is '
'only supported on desktop platforms.');
usesWebOptions(hide: !verboseHelp);
usesTargetOption();
usesPortOptions();
......@@ -153,6 +160,7 @@ abstract class RunCommandBase extends FlutterCommand with DeviceBasedDevelopment
if (buildInfo.mode.isRelease) {
return DebuggingOptions.disabled(
buildInfo,
dartEntrypointArgs: stringsArg('dart-entrypoint-args'),
hostname: featureFlags.isWebEnabled ? stringArg('web-hostname') : '',
port: featureFlags.isWebEnabled ? stringArg('web-port') : '',
webUseSseForDebugProxy: featureFlags.isWebEnabled && stringArg('web-server-debug-protocol') == 'sse',
......@@ -167,6 +175,7 @@ abstract class RunCommandBase extends FlutterCommand with DeviceBasedDevelopment
startPaused: boolArg('start-paused'),
disableServiceAuthCodes: boolArg('disable-service-auth-codes'),
disableDds: boolArg('disable-dds'),
dartEntrypointArgs: stringsArg('dart-entrypoint-args'),
dartFlags: stringArg('dart-flags') ?? '',
useTestFonts: argParser.options.containsKey('use-test-fonts') && boolArg('use-test-fonts'),
enableSoftwareRendering: argParser.options.containsKey('enable-software-rendering') && boolArg('enable-software-rendering'),
......
......@@ -139,6 +139,7 @@ abstract class DesktopDevice extends Device {
final Process process = await _processManager.start(
<String>[
executable,
...?debuggingOptions?.dartEntrypointArgs,
],
environment: _computeEnvironment(debuggingOptions, traceStartup, route),
);
......
......@@ -835,6 +835,7 @@ class DebuggingOptions {
this.startPaused = false,
this.disableServiceAuthCodes = false,
this.disableDds = false,
this.dartEntrypointArgs = const <String>[],
this.dartFlags = '',
this.enableSoftwareRendering = false,
this.skiaDeterministicRendering = false,
......@@ -865,6 +866,7 @@ class DebuggingOptions {
}) : debuggingEnabled = true;
DebuggingOptions.disabled(this.buildInfo, {
this.dartEntrypointArgs = const <String>[],
this.port,
this.hostname,
this.webEnableExposeUrl,
......@@ -902,6 +904,7 @@ class DebuggingOptions {
final BuildInfo buildInfo;
final bool startPaused;
final String dartFlags;
final List<String> dartEntrypointArgs;
final bool disableServiceAuthCodes;
final bool disableDds;
final bool enableSoftwareRendering;
......
......@@ -247,6 +247,29 @@ void main() {
expect(device.createDevFSWriter(null, ''), isA<LocalDevFSWriter>());
});
testWithoutContext('startApp supports dartEntrypointArgs', () async {
final Completer<void> completer = Completer<void>();
final FakeProcessManager processManager = FakeProcessManager.list(<FakeCommand>[
FakeCommand(
command: const <String>['debug', 'arg1', 'arg2'],
stdout: 'Observatory listening on http://127.0.0.1/0\n',
completer: completer
),
]);
final FakeDesktopDevice device = setUpDesktopDevice(processManager: processManager);
final FakeApplicationPackage package = FakeApplicationPackage();
final LaunchResult result = await device.startApp(
package,
prebuiltApplication: true,
debuggingOptions: DebuggingOptions.enabled(
BuildInfo.debug,
dartEntrypointArgs: <String>['arg1', 'arg2']
),
);
expect(result.started, true);
});
}
FakeDesktopDevice setUpDesktopDevice({
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment