executePatch method
Executes shorebird patch <platform>.
Implementation
Future<ShorebirdCommandResult> executePatch({
required String projectPath,
required BuildPlatform platform,
required bool dryRun,
String? releaseVersion,
List<String> extraArgs = const [],
}) async {
final args = buildPatchArgs(
platform: platform,
releaseVersion: releaseVersion,
extraArgs: extraArgs,
);
final commandString = 'shorebird ${args.join(' ')}';
if (dryRun) {
return ShorebirdCommandResult.success(
commandString: commandString,
executedSteps: [
'[DRY-RUN] Verified Shorebird CLI installation.',
'[DRY-RUN] Command preview: $commandString',
],
);
}
final steps = <String>['Invoking: $commandString'];
try {
final result = await _runner.run(
'shorebird',
args,
workingDirectory: projectPath,
);
if (result.exitCode != 0) {
final errStr = result.stderr.toString().trim();
final outStr = result.stdout.toString().trim();
final combined = errStr.isNotEmpty ? errStr : outStr;
return ShorebirdCommandResult.failure(
commandString: commandString,
exitCode: result.exitCode,
stdout: outStr,
stderr: errStr,
executedSteps: steps,
errors: [
'Shorebird patch failed with exit code ${result.exitCode}.',
if (combined.isNotEmpty) combined,
],
);
}
steps.add('Shorebird patch applied successfully.');
return ShorebirdCommandResult.success(
commandString: commandString,
stdout: result.stdout.toString(),
stderr: result.stderr.toString(),
executedSteps: steps,
);
} catch (e) {
return ShorebirdCommandResult.failure(
commandString: commandString,
executedSteps: steps,
errors: ['Failed to execute Shorebird process: $e'],
);
}
}