BuildStepConfig.fromJson constructor
Creates the right BuildStepConfig subclass from json.
Implementation
factory BuildStepConfig.fromJson(Map<String, dynamic> json) {
final type = json['type'] as String?;
// Strip the 'type' key before passing to the concrete class fromJson
// since the concrete classes don't have a 'type' field.
final stepJson = Map<String, dynamic>.from(json)..remove('type');
return switch (type) {
'cmake_configure' => CmakeConfigureStepConfig.fromJson(stepJson),
'cmake_build' => CmakeBuildStepConfig.fromJson(stepJson),
'export_artifact' => ExportArtifactStepConfig.fromJson(stepJson),
'command' => CommandStepConfig.fromJson(stepJson),
'download_archive' => DownloadArchiveStepConfig.fromJson(stepJson),
'git_checkout' => GitCheckoutStepConfig.fromJson(stepJson),
'git_apply_patch' => GitApplyPatchStepConfig.fromJson(stepJson),
'copy' => CopyStepConfig.fromJson(stepJson),
'strip' => StripStepConfig.fromJson(stepJson),
_ => throw FormatException('Unknown build step type: $type'),
};
}