Skip to content

Commit

Permalink
use the default value, instead of the current one, when toggling a bo…
Browse files Browse the repository at this point in the history
…olean flag, to allow for future flag duplication
  • Loading branch information
spytheman committed Sep 4, 2024
1 parent 8f88e2c commit a7bd383
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion vlib/flag/flag_to.v
Original file line number Diff line number Diff line change
Expand Up @@ -832,6 +832,7 @@ fn keep_at_max(str string, max int) string {
pub fn (fm FlagMapper) to_struct[T](defaults ?T) !T {
// Generate T result
mut result := defaults or { T{} }
the_default := defaults or { T{} }

$if T is $struct {
struct_name := T.name
Expand Down Expand Up @@ -907,7 +908,7 @@ pub fn (fm FlagMapper) to_struct[T](defaults ?T) !T {
if arg := f.arg {
return error('can not assign `${arg}` to bool field `${field.name}`')
}
result.$(field.name) = !result.$(field.name)
result.$(field.name) = !the_default.$(field.name)
} $else $if field.typ is string {
trace_dbg_println('${@FN}: assigning (string) ${struct_name}.${field.name} = ${f.arg or {
'ERROR'
Expand Down

0 comments on commit a7bd383

Please sign in to comment.