Skip to content

Commit

Permalink
v0.4.1 - count function fix to understand different number types
Browse files Browse the repository at this point in the history
  • Loading branch information
greg-szabo committed Jul 16, 2019
1 parent 37f292a commit dead45d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
27 changes: 23 additions & 4 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import (
"github.com/spf13/pflag"
"github.com/spf13/viper"
"io/ioutil"
"math"
"os"
"path/filepath"
"strconv"
"strings"
"text/template"
)
Expand Down Expand Up @@ -58,9 +58,28 @@ func substitute(name string) interface{} {
return dictionary[name]
}

func counter(num float64) interface{} {
var result []int
for i := 0 ; i < int(math.Floor(num)) ; i++ {
func counter(input interface{}) interface{} {
var num uint64
if numf64, ok := input.(float64); ok {
num = uint64(numf64)
} else {
if numi, ok := input.(uint64); ok {
num = numi
} else {
if nums, ok := input.(string); ok {
var err error
num, err = strconv.ParseUint(nums, 10, 64)
if err != nil {
panic(err)
}
} else {
panic(errors.New(fmt.Sprintf("cannot convert input to number: %s", input)))
}
}
}
var result []uint64
var i uint64
for i = 0 ; i < num ; i++ {
result = append(result, i)
}
return result
Expand Down
2 changes: 1 addition & 1 deletion defaults/defaults.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package defaults

// Application version
const Version = "0.4.0"
const Version = "0.4.1"
2 changes: 1 addition & 1 deletion test_dictionaries/test.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@
],
"substitute_test": "map",
"number_test": 5
}
}

0 comments on commit dead45d

Please sign in to comment.