mirror of
https://github.com/mikefarah/yq.git
synced 2026-07-07 22:35:37 +00:00
Add handle for int Issue 314
This commit is contained in:
parent
27604289f4
commit
339cc3a12d
@ -1,8 +1,7 @@
|
||||
package yqlib
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
)
|
||||
import "strconv"
|
||||
import "strings"
|
||||
|
||||
type ValueParser interface {
|
||||
ParseValue(argument string) interface{}
|
||||
@ -17,11 +16,19 @@ func NewValueParser() ValueParser {
|
||||
func (v *valueParser) ParseValue(argument string) interface{} {
|
||||
var value, err interface{}
|
||||
var inQuotes = len(argument) > 0 && argument[0] == '"'
|
||||
var isDot = strings.Contains(argument, ".")
|
||||
if !inQuotes {
|
||||
if isDot {
|
||||
value, err = strconv.ParseFloat(argument, 64)
|
||||
if err == nil {
|
||||
return value
|
||||
}
|
||||
} else {
|
||||
value, err = strconv.ParseInt(argument, 10, 64)
|
||||
if err == nil {
|
||||
return value
|
||||
}
|
||||
}
|
||||
value, err = strconv.ParseBool(argument)
|
||||
if err == nil {
|
||||
return value
|
||||
|
||||
Loading…
Reference in New Issue
Block a user