This commit is contained in:
2025-10-12 17:08:03 +04:00
parent 4cf3aa6d5c
commit 58d3d9daa0
3 changed files with 32 additions and 22 deletions

View File

@@ -85,10 +85,7 @@ fn should_skip_field(attrs []string) bool {
|| attr_clean.starts_with('skip;')
|| attr_clean.ends_with(';skip')
|| attr_clean.contains(';skip;')
|| attr_clean == 'skipdecode'
|| attr_clean.starts_with('skipdecode;')
|| attr_clean.ends_with(';skipdecode')
|| attr_clean.contains(';skipdecode;') {
{
return true
}
}

View File

@@ -53,5 +53,5 @@ fn test_encode_skip_multiple_attrs() ! {
assert script.contains('name:test')
assert !script.contains('skip1')
assert !script.contains('skip2')
assert !script.contains('skip3')
assert script.contains('skip3')
}

View File

@@ -13,6 +13,19 @@ pub fn (params Params) decode[T](args T) !T {
pub fn (params Params) decode_struct[T](start T) !T {
mut t := T{}
$for field in T.fields {
mut should_skip := false
for attr in field.attrs {
attr_clean := attr.to_lower().replace(' ', '').replace('\t', '')
// Handle various skip attribute formats:
// @[skip], @[skip;...], @[...;skip], @[...;skip;...], etc.
if attr_clean == 'skip' || attr_clean.starts_with('skip;')
|| attr_clean.ends_with(';skip') || attr_clean.contains(';skip;') {
should_skip = true
break
}
}
println('Field: ${field.name}, should_skip: ${should_skip}, attrs: ${field.attrs}')
if ! should_skip {
$if field.is_enum {
t.$(field.name) = params.get_int(field.name) or { int(t.$(field.name)) }
} $else {
@@ -31,14 +44,14 @@ pub fn (params Params) decode_struct[T](start T) !T {
}
}
}
}
return t
}
pub fn (params Params) decode_value[T](val T, key string) !T {
// $if T is $option {
// return error("is option")
// }
// value := params.get(field.name)!
$if T is $option {
return error("is option")
}
// TODO: handle required fields
if !params.exists(key) {