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 VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v2.0.5
v2.0.6
82 changes: 76 additions & 6 deletions flesh.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,36 +8,84 @@ import (
)

func NewFlesh(thing interface{}) Flesh {
return &figFlesh{Flesh: thing}
f := figFlesh{Flesh: thing}
return &f
}

func (flesh *figFlesh) ToString() string {
f, _ := toString(flesh.Flesh)
f, e := toString(flesh.Flesh)
if e != nil {
isFlesh, ok := flesh.Flesh.(*figFlesh)
if ok {
f, e = toString(isFlesh.Flesh)
if e != nil {
return ""
}
}
}
return f
}

func (flesh *figFlesh) ToInt() int {
f, _ := toInt(flesh.Flesh)
f, e := toInt(flesh.Flesh)
if e != nil {
isFlesh, ok := flesh.Flesh.(*figFlesh)
if ok {
f, e = toInt(isFlesh.Flesh)
if e != nil {
return 0
}
}
}
return f
}

func (flesh *figFlesh) ToInt64() int64 {
f, _ := toInt64(flesh.Flesh)
f, e := toInt64(flesh.Flesh)
if e != nil {
isFlesh, ok := flesh.Flesh.(*figFlesh)
if ok {
f, e = toInt64(isFlesh.Flesh)
if e != nil {
return 0
}
}
}
return f
}

func (flesh *figFlesh) ToBool() bool {
f, _ := toBool(flesh.Flesh)
f, e := toBool(flesh.Flesh)
if e != nil {
isFlesh, ok := flesh.Flesh.(*figFlesh)
if ok {
f, e = toBool(isFlesh.Flesh)
if e != nil {
return false
}
}
}
return f
}

func (flesh *figFlesh) ToFloat64() float64 {
f, _ := toFloat64(flesh.Flesh)
f, e := toFloat64(flesh.Flesh)
if e != nil {
isFlesh, ok := flesh.Flesh.(*figFlesh)
if ok {
f, e = toFloat64(isFlesh.Flesh)
if e != nil {
return 0.0
}
}
}
return f
}

func (flesh *figFlesh) ToDuration() time.Duration {
switch f := flesh.Flesh.(type) {
case *figFlesh:
return f.ToDuration()
case time.Duration:
return f
case *time.Duration:
Expand Down Expand Up @@ -77,6 +125,8 @@ func (flesh *figFlesh) ToUnitDuration() time.Duration {

func (flesh *figFlesh) ToList() []string {
switch f := flesh.Flesh.(type) {
case *figFlesh:
return f.ToList()
case *ListFlag:
return f.Values()
case []string:
Expand Down Expand Up @@ -105,6 +155,8 @@ func (flesh *figFlesh) ToMap() map[string]string {
return f
}
switch ft := flesh.Flesh.(type) {
case *figFlesh:
return ft.ToMap()
case *MapFlag:
// Create a new map and copy the key-value pairs
fu := make(map[string]string, len(*ft.values))
Expand Down Expand Up @@ -152,6 +204,8 @@ func (flesh *figFlesh) Is(mutagenesis Mutagenesis) bool {

func (flesh *figFlesh) IsString() bool {
switch f := flesh.Flesh.(type) {
case *figFlesh:
return f.IsString()
case string:
return true
case *string:
Expand All @@ -163,6 +217,8 @@ func (flesh *figFlesh) IsString() bool {

func (flesh *figFlesh) IsInt() bool {
switch f := flesh.Flesh.(type) {
case *figFlesh:
return f.IsInt()
case int:
return true
case *int:
Expand All @@ -174,6 +230,8 @@ func (flesh *figFlesh) IsInt() bool {

func (flesh *figFlesh) IsInt64() bool {
switch f := flesh.Flesh.(type) {
case *figFlesh:
return f.IsInt64()
case int64:
return true
case *int64:
Expand All @@ -185,6 +243,8 @@ func (flesh *figFlesh) IsInt64() bool {

func (flesh *figFlesh) IsBool() bool {
switch f := flesh.Flesh.(type) {
case *figFlesh:
return f.IsBool()
case bool:
return true
case *bool:
Expand All @@ -197,6 +257,8 @@ func (flesh *figFlesh) IsBool() bool {

func (flesh *figFlesh) IsFloat64() bool {
switch f := flesh.Flesh.(type) {
case *figFlesh:
return f.IsFloat64()
case float64:
return true
case *float64:
Expand All @@ -208,6 +270,8 @@ func (flesh *figFlesh) IsFloat64() bool {

func (flesh *figFlesh) IsDuration() bool {
switch f := flesh.Flesh.(type) {
case *figFlesh:
return f.IsDuration()
case time.Duration:
return true
case *time.Duration:
Expand All @@ -220,6 +284,8 @@ func (flesh *figFlesh) IsDuration() bool {

func (flesh *figFlesh) IsUnitDuration() bool {
switch f := flesh.Flesh.(type) {
case *figFlesh:
return f.IsUnitDuration()
case time.Duration:
return true
case *time.Duration:
Expand All @@ -232,6 +298,8 @@ func (flesh *figFlesh) IsUnitDuration() bool {

func (flesh *figFlesh) IsList() bool {
switch f := flesh.Flesh.(type) {
case *figFlesh:
return f.IsList()
case *ListFlag:
return true
case ListFlag:
Expand Down Expand Up @@ -278,6 +346,8 @@ func (flesh *figFlesh) IsMap() bool {
return ok
}
switch f := flesh.Flesh.(type) {
case *figFlesh:
return f.IsMap()
case *MapFlag:
return true
case MapFlag:
Expand Down
3 changes: 3 additions & 0 deletions flesh_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ func TestNewFlesh(t *testing.T) {
assert.Equal(t, 0, NewFlesh(t.Name()).ToInt())
assert.Equal(t, map[string]string{}, NewFlesh(t.Name()).ToMap())
assert.Equal(t, []string{t.Name()}, NewFlesh(t.Name()).ToList())
var x interface{}
assert.NotNil(t, NewFlesh(x))
assert.NotNil(t, NewFlesh(x).ToString())
}

func TestFleshInterface(t *testing.T) {
Expand Down
Loading