Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
strategy:
matrix:
os: [ ubuntu-latest, macos-latest, windows-latest ]
go-version: [ '1.23.2', '1.24.2' ]
go-version: [ '1.23.4' ]
fail-fast: false

steps:
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v2.1.0
v2.1.1
169 changes: 110 additions & 59 deletions mutations_new.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package figtree

import (
"fmt"
"strings"
"time"
)
Expand All @@ -9,8 +10,12 @@ import (
func (tree *figTree) NewString(name string, value string, usage string) Plant {
tree.mu.Lock()
defer tree.mu.Unlock()
tree.activateFlagSet()
name = strings.ToLower(name)
if _, exists := tree.figs[name]; exists {
tree.problems = append(tree.problems, fmt.Errorf("name '%s' already exists", name))
return tree
}
tree.activateFlagSet()
vPtr := &Value{
Value: value,
Mutagensis: tString,
Expand All @@ -27,30 +32,32 @@ func (tree *figTree) NewString(name string, value string, usage string) Plant {
Rules: make([]RuleKind, 0),
}
tree.figs[name] = def
theWitheredFig, exists := tree.withered[name]
if !exists {
if _, exists := tree.withered[name]; !exists {
tree.withered[name] = witheredFig{
name: name,
Value: *vPtr,
Mutagenesis: tString,
}
}
tree.withered[name] = theWitheredFig
return tree
}

// NewBool with validator and withered support
func (tree *figTree) NewBool(name string, value bool, usage string) Plant {
tree.mu.Lock()
defer tree.mu.Unlock()
tree.activateFlagSet()
name = strings.ToLower(name)
if _, exists := tree.figs[name]; exists {
tree.problems = append(tree.problems, fmt.Errorf("name '%s' already exists", name))
return tree
}
tree.activateFlagSet()
v := &Value{
Value: &value, // Store a persistent pointer to the bool value
Value: value,
Mutagensis: tBool,
}
tree.flagSet.BoolVar(v.Value.(*bool), name, value, usage) // Use the persistent pointer directly
tree.values.Store(name, v)
tree.flagSet.Var(v, name, usage)
def := &figFruit{
name: name,
usage: usage,
Expand All @@ -61,10 +68,12 @@ func (tree *figTree) NewBool(name string, value bool, usage string) Plant {
Rules: make([]RuleKind, 0),
}
tree.figs[name] = def
tree.withered[name] = witheredFig{
name: name,
Value: *v,
Mutagenesis: tBool,
if _, exists := tree.withered[name]; !exists {
tree.withered[name] = witheredFig{
name: name,
Value: *v,
Mutagenesis: tBool,
}
}
return tree
}
Expand All @@ -73,8 +82,12 @@ func (tree *figTree) NewBool(name string, value bool, usage string) Plant {
func (tree *figTree) NewInt(name string, value int, usage string) Plant {
tree.mu.Lock()
defer tree.mu.Unlock()
tree.activateFlagSet()
name = strings.ToLower(name)
if _, exists := tree.figs[name]; exists {
tree.problems = append(tree.problems, fmt.Errorf("name '%s' already exists", name))
return tree
}
tree.activateFlagSet()
v := &Value{
Value: value,
Mutagensis: tInt,
Expand All @@ -91,20 +104,26 @@ func (tree *figTree) NewInt(name string, value int, usage string) Plant {
Rules: make([]RuleKind, 0),
}
tree.figs[name] = def
tree.withered[name] = witheredFig{
name: name,
Value: *v,
Mutagenesis: tInt,
} // Initialize withered with a copy
if _, exists := tree.withered[name]; !exists {
tree.withered[name] = witheredFig{
name: name,
Value: *v,
Mutagenesis: tInt,
} // Initialize withered with a copy
}
return tree
}

// NewInt64 with validator and withered support
func (tree *figTree) NewInt64(name string, value int64, usage string) Plant {
tree.mu.Lock()
defer tree.mu.Unlock()
tree.activateFlagSet()
name = strings.ToLower(name)
if _, exists := tree.figs[name]; exists {
tree.problems = append(tree.problems, fmt.Errorf("name '%s' already exists", name))
return tree
}
tree.activateFlagSet()
v := &Value{
Value: value,
Mutagensis: tInt64,
Expand All @@ -121,10 +140,12 @@ func (tree *figTree) NewInt64(name string, value int64, usage string) Plant {
Rules: make([]RuleKind, 0),
}
tree.figs[name] = def
tree.withered[name] = witheredFig{
name: name,
Value: *v,
Mutagenesis: tInt64,
if _, exists := tree.withered[name]; !exists {
tree.withered[name] = witheredFig{
name: name,
Value: *v,
Mutagenesis: tInt64,
}
}
return tree
}
Expand All @@ -133,8 +154,12 @@ func (tree *figTree) NewInt64(name string, value int64, usage string) Plant {
func (tree *figTree) NewFloat64(name string, value float64, usage string) Plant {
tree.mu.Lock()
defer tree.mu.Unlock()
tree.activateFlagSet()
name = strings.ToLower(name)
if _, exists := tree.figs[name]; exists {
tree.problems = append(tree.problems, fmt.Errorf("name '%s' already exists", name))
return tree
}
tree.activateFlagSet()
v := &Value{
Value: value,
Mutagensis: tFloat64,
Expand All @@ -151,10 +176,12 @@ func (tree *figTree) NewFloat64(name string, value float64, usage string) Plant
Rules: make([]RuleKind, 0),
}
tree.figs[name] = def
tree.withered[name] = witheredFig{
name: name,
Value: *v,
Mutagenesis: tFloat64,
if _, exists := tree.withered[name]; !exists {
tree.withered[name] = witheredFig{
name: name,
Value: *v,
Mutagenesis: tFloat64,
}
}
return tree
}
Expand All @@ -163,8 +190,12 @@ func (tree *figTree) NewFloat64(name string, value float64, usage string) Plant
func (tree *figTree) NewDuration(name string, value time.Duration, usage string) Plant {
tree.mu.Lock()
defer tree.mu.Unlock()
tree.activateFlagSet()
name = strings.ToLower(name)
if _, exists := tree.figs[name]; exists {
tree.problems = append(tree.problems, fmt.Errorf("name '%s' already exists", name))
return tree
}
tree.activateFlagSet()
v := &Value{
Value: value,
Mutagensis: tDuration,
Expand All @@ -181,10 +212,12 @@ func (tree *figTree) NewDuration(name string, value time.Duration, usage string)
Rules: make([]RuleKind, 0),
}
tree.figs[name] = def
tree.withered[name] = witheredFig{
name: name,
Value: *v,
Mutagenesis: tDuration,
if _, exists := tree.withered[name]; !exists {
tree.withered[name] = witheredFig{
name: name,
Value: *v,
Mutagenesis: tDuration,
}
}
return tree
}
Expand All @@ -193,8 +226,12 @@ func (tree *figTree) NewDuration(name string, value time.Duration, usage string)
func (tree *figTree) NewUnitDuration(name string, value, units time.Duration, usage string) Plant {
tree.mu.Lock()
defer tree.mu.Unlock()
tree.activateFlagSet()
name = strings.ToLower(name)
if _, exists := tree.figs[name]; exists {
tree.problems = append(tree.problems, fmt.Errorf("name '%s' already exists", name))
return tree
}
tree.activateFlagSet()
v := &Value{
Value: value * units,
Mutagensis: tUnitDuration,
Expand All @@ -211,10 +248,12 @@ func (tree *figTree) NewUnitDuration(name string, value, units time.Duration, us
Rules: make([]RuleKind, 0),
}
tree.figs[name] = def
tree.withered[name] = witheredFig{
name: name,
Value: *v,
Mutagenesis: tUnitDuration,
if _, exists := tree.withered[name]; !exists {
tree.withered[name] = witheredFig{
name: name,
Value: *v,
Mutagenesis: tUnitDuration,
}
}
return tree
}
Expand All @@ -226,8 +265,12 @@ func (tree *figTree) NewList(name string, value []string, usage string) Plant {
if tree.HasRule(RuleNoLists) {
return tree
}
tree.activateFlagSet()
name = strings.ToLower(name)
if _, exists := tree.figs[name]; exists {
tree.problems = append(tree.problems, fmt.Errorf("name '%s' already exists", name))
return tree
}
tree.activateFlagSet()
v := &Value{
Value: ListFlag{values: value},
Mutagensis: tList,
Expand All @@ -244,15 +287,17 @@ func (tree *figTree) NewList(name string, value []string, usage string) Plant {
Rules: make([]RuleKind, 0),
}
tree.figs[name] = def
witheredVal := make([]string, len(value))
copy(witheredVal, value)
tree.withered[name] = witheredFig{
name: name,
Value: Value{
Value: witheredVal,
Mutagensis: tList,
},
Mutagenesis: tList,
if _, exists := tree.withered[name]; !exists {
witheredVal := make([]string, len(value))
copy(witheredVal, value)
tree.withered[name] = witheredFig{
name: name,
Value: Value{
Value: witheredVal,
Mutagensis: tList,
},
Mutagenesis: tList,
}
}
return tree
}
Expand All @@ -264,8 +309,12 @@ func (tree *figTree) NewMap(name string, value map[string]string, usage string)
if tree.HasRule(RuleNoMaps) {
return tree
}
tree.activateFlagSet()
name = strings.ToLower(name)
if _, exists := tree.figs[name]; exists {
tree.problems = append(tree.problems, fmt.Errorf("name '%s' already exists", name))
return tree
}
tree.activateFlagSet()
v := &Value{
Value: MapFlag{values: value},
Mutagensis: tMap,
Expand All @@ -282,17 +331,19 @@ func (tree *figTree) NewMap(name string, value map[string]string, usage string)
Rules: make([]RuleKind, 0),
}
tree.figs[name] = def
witheredVal := make(map[string]string)
for k, v := range value {
witheredVal[k] = v
}
tree.withered[name] = witheredFig{
name: name,
Value: Value{
Value: witheredVal,
Mutagensis: tree.MutagenesisOf(witheredVal),
},
Mutagenesis: tMap,
if _, exists := tree.withered[name]; !exists {
witheredVal := make(map[string]string)
for k, v := range value {
witheredVal[k] = v
}
tree.withered[name] = witheredFig{
name: name,
Value: Value{
Value: witheredVal,
Mutagensis: tree.MutagenesisOf(witheredVal),
},
Mutagenesis: tMap,
}
}
return tree
}
Loading