update if
This commit is contained in:
parent
8480cebe4b
commit
d6059b9d11
5 changed files with 75 additions and 9 deletions
|
|
@ -19,7 +19,7 @@ pipeline:
|
|||
#일반적인 if문과 동일
|
||||
- if:
|
||||
#property의 내용은 기본 dynamic(Object)형으로써, 비교시 정확한 캐스팅 필요, 적지 않을시 기본 string
|
||||
condition-string: <!property:git-rev> == <!property:old-git-rev>
|
||||
condition-string: <!property.git-rev> == <!property.old-git-rev>
|
||||
on-false:
|
||||
- exe: zip
|
||||
|
||||
|
|
|
|||
|
|
@ -23,6 +23,8 @@ class DataPipeline {
|
|||
|
||||
@JsonSerializable()
|
||||
class DataIf implements DataValidator {
|
||||
late String? condition;
|
||||
late String? type;
|
||||
@JsonKey(name: 'condition-int')
|
||||
late String? condition_int;
|
||||
@JsonKey(name: 'condition-float')
|
||||
|
|
@ -43,15 +45,27 @@ class DataIf implements DataValidator {
|
|||
@override
|
||||
PipelineValidateResult validate() {
|
||||
var result = PipelineValidateResult();
|
||||
if (condition_int == null &&
|
||||
condition_float == null &&
|
||||
condition_string == null &&
|
||||
condition_version == null &&
|
||||
condition_bool == null) {
|
||||
if (condition_int != null) {
|
||||
condition = condition_int!;
|
||||
type = 'int';
|
||||
} else if (condition_float != null) {
|
||||
condition = condition_float!;
|
||||
type = 'float';
|
||||
} else if (condition_string != null) {
|
||||
condition = condition_string!;
|
||||
type = 'string';
|
||||
} else if (condition_version != null) {
|
||||
condition = condition_version!;
|
||||
type = 'version';
|
||||
} else if (condition_bool != null) {
|
||||
condition = condition_bool!;
|
||||
type = 'bool';
|
||||
} else {
|
||||
result.message = 'If syntax requires a condition.';
|
||||
result.enable = false;
|
||||
return result;
|
||||
}
|
||||
|
||||
if (on_true == null && on_false == null) {
|
||||
result.message = 'If syntax requires on-true or on-false.';
|
||||
result.enable = false;
|
||||
|
|
|
|||
|
|
@ -17,6 +17,8 @@ Map<String, dynamic> _$DataPipelineToJson(DataPipeline instance) =>
|
|||
};
|
||||
|
||||
DataIf _$DataIfFromJson(Map<String, dynamic> json) => DataIf()
|
||||
..condition = json['condition'] as String?
|
||||
..type = json['type'] as String?
|
||||
..condition_int = json['condition-int'] as String?
|
||||
..condition_float = json['condition-float'] as String?
|
||||
..condition_string = json['condition-string'] as String?
|
||||
|
|
@ -26,6 +28,8 @@ DataIf _$DataIfFromJson(Map<String, dynamic> json) => DataIf()
|
|||
..on_false = json['on-false'] as List<dynamic>?;
|
||||
|
||||
Map<String, dynamic> _$DataIfToJson(DataIf instance) => <String, dynamic>{
|
||||
'condition': instance.condition,
|
||||
'type': instance.type,
|
||||
'condition-int': instance.condition_int,
|
||||
'condition-float': instance.condition_float,
|
||||
'condition-string': instance.condition_string,
|
||||
|
|
|
|||
|
|
@ -49,6 +49,7 @@ class PipelineValidateResult {
|
|||
late String? message;
|
||||
late bool enable = true;
|
||||
late List<PipelineExecutor> exeList = [];
|
||||
|
||||
Pipeline? get pipeline {
|
||||
if (exeList.isNotEmpty) {
|
||||
return Pipeline(exeList);
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
import 'package:dart_framework/utils/system_util.dart';
|
||||
import 'package:oto_cli/cli/cli.dart';
|
||||
import 'package:oto_cli/oto/commands/command.dart';
|
||||
import 'package:oto_cli/oto/data/pipeline_data.dart';
|
||||
import 'package:oto_cli/oto/pipeline/pipeline.dart';
|
||||
import 'package:oto_cli/oto/pipeline/pipeline_exe.dart';
|
||||
|
|
@ -7,6 +9,9 @@ class PipelineIf extends PipelineExecutor {
|
|||
late DataIf _data;
|
||||
late Pipeline? _pipelineTrue;
|
||||
late Pipeline? _pipelineFalse;
|
||||
Map<String, bool Function(String, String, dynamic Function(String))>
|
||||
_conditions = {};
|
||||
Map<String, dynamic Function(String value)> _types = {};
|
||||
|
||||
@override
|
||||
PipelineValidateResult initialize(Map<String, dynamic> set) {
|
||||
|
|
@ -16,6 +21,7 @@ class PipelineIf extends PipelineExecutor {
|
|||
if (!dataValidateResult.enable) {
|
||||
return dataValidateResult;
|
||||
}
|
||||
|
||||
//set true task
|
||||
var validateResult = validateTasks(_data.on_true);
|
||||
if (!validateResult.enable) {
|
||||
|
|
@ -30,14 +36,55 @@ class PipelineIf extends PipelineExecutor {
|
|||
}
|
||||
_pipelineFalse = validateResult.pipeline;
|
||||
|
||||
_conditions = {
|
||||
' < ': (v0, v1, caster) => caster(v0) < caster(v1),
|
||||
' <= ': (v0, v1, caster) => caster(v0) <= caster(v1),
|
||||
' > ': (v0, v1, caster) => caster(v0) > caster(v1),
|
||||
' >= ': (v0, v1, caster) => caster(v0) >= caster(v1),
|
||||
' == ': (v0, v1, caster) => caster(v0) == caster(v1),
|
||||
' != ': (v0, v1, caster) => caster(v0) != caster(v1),
|
||||
};
|
||||
_types = {
|
||||
'int': (value) => int.parse(value),
|
||||
'float': (value) => double.parse(value),
|
||||
'string': (value) => value,
|
||||
'bool': (value) => value.toLowerCase() == 'true',
|
||||
'version': (value) => value
|
||||
};
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@override
|
||||
Future execute() async {
|
||||
//To-do: check true or false
|
||||
await _pipelineTrue?.execute();
|
||||
await _pipelineFalse?.execute();
|
||||
var result = checkCondition(_data.condition!);
|
||||
await CLI.println('[IF] (${result.conditionValue}) : ${result.result}',
|
||||
color: Color.magentaStrong);
|
||||
if (result.result) {
|
||||
await _pipelineTrue?.execute();
|
||||
} else {
|
||||
await _pipelineFalse?.execute();
|
||||
}
|
||||
return simpleFuture;
|
||||
}
|
||||
|
||||
IfConditionCheckResult checkCondition(String condition) {
|
||||
var result = IfConditionCheckResult();
|
||||
for (var item in _conditions.entries) {
|
||||
if (condition.contains(item.key)) {
|
||||
var list = condition.split(item.key);
|
||||
var value0 = Command.replaceTagValue(list[0]);
|
||||
var value1 = Command.replaceTagValue(list[1]);
|
||||
result.conditionValue = '$value0${item.key}$value1';
|
||||
result.result = item.value(value0, value1, _types[_data.type]!);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
class IfConditionCheckResult {
|
||||
late String conditionValue;
|
||||
late bool result;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue