oto/lib/oto/pipeline/pipeline_foreach.dart
toki ac1c42448e refactor: split build_ios and git commands, add cli styling, improve pipeline system
- Split BuildIOS command into build_ios_archive and build_ios_build
- Split Git command into git_branch, git_remote, git_revision, git_stash
- Add cli_style.dart and printer.dart for consistent CLI output
- Add macos_signing.dart for macOS/iOS code signing
- Refactor pipeline system (pipeline, pipeline_condition, pipeline_contain, etc.)
- Update tag_system, defined_data, pipeline_data
- Update application and command files for new structure
- Add tests for new command catalog and core functionality
- Update README with new features
2026-05-20 20:50:59 +09:00

90 lines
2.6 KiB
Dart

import 'package:dart_framework/utils/system_util.dart';
import 'package:oto/cli/cli.dart';
import 'package:oto/oto/application.dart';
import 'package:oto/oto/core/tag_system.dart';
import 'package:oto/oto/data/pipeline_data.dart';
import 'package:oto/oto/pipeline/pipeline.dart';
import 'package:oto/oto/pipeline/pipeline_exe.dart';
/// Iterates over a List or Map and executes on-do pipeline for each element.
/// - List: sets setValue for each item.
/// - Map: sets setKey (optional) and setValue for each key-value pair.
///
/// Example YAML:
/// ```yaml
/// # List iteration
/// - foreach:
/// iterator: <!property.arr>
/// setValue: <@property.item>
/// on-do:
/// - exe: processItem
///
/// # Map iteration
/// - foreach:
/// iterator: <!property.map>
/// setKey: <@property.key> # optional
/// setValue: <@property.value>
/// on-do:
/// - exe: processEntry
/// ```
class PipelineForeach extends PipelineExecutor {
late Pipeline? _pipelineOnDo;
late DataForeach data;
@override
PipelineValidateResult initialize(Map<String, dynamic> set) {
data = DataForeach.fromJson(set.values.first);
var dataValidateResult = data.validate();
if (!dataValidateResult.enable) {
return dataValidateResult;
}
//set do task
var validateResult =
PipelineExecutor.validateTasks(data.on_do, context: context);
if (!validateResult.enable) {
return validateResult;
}
_pipelineOnDo = validateResult.pipeline;
return PipelineValidateResult();
}
@override
Future execute() async {
var iterator = TagSystem.replaceTagValue(data.iterator, context: runtimeContext);
var iteratorType = '';
if(iterator != null)
{
if(iterator is List)
{
iteratorType = 'List';
var elementTag = data.setValue;
for(var item in iterator)
{
await TagSystem.setPropertyValue(elementTag, item, context: runtimeContext);
await _pipelineOnDo?.execute();
}
}
if(iterator is Map)
{
iteratorType = 'Map';
var keyTag = data.setKey;
var elementTag = data.setValue;
for(var pair in iterator.entries)
{
if(keyTag != null)
{
await TagSystem.setPropertyValue(keyTag, pair.key, context: runtimeContext);
}
await TagSystem.setPropertyValue(elementTag, pair.value, context: runtimeContext);
await _pipelineOnDo?.execute();
}
}
await CLI.println('[Pipeline-Foreach ($iteratorType)]', color: Color.magentaStrong);
Application.log(' - Foreach complete. Loop out');
}
return simpleFuture;
}
}