From 1a4d8158ba44c84a87c22fa72b8c270b7efeaa40 Mon Sep 17 00:00:00 2001 From: Mike Farah Date: Mon, 20 Jan 2020 08:42:08 +1100 Subject: [PATCH] Removed custom value parsing logic --- cmd/merge.go | 3 ++- cmd/root.go | 3 ++- cmd/utils.go | 9 +++++---- pkg/yqlib/value_parser.go | 30 +++--------------------------- pkg/yqlib/value_parser_test.go | 8 ++------ yq.go | 3 ++- 6 files changed, 16 insertions(+), 40 deletions(-) diff --git a/cmd/merge.go b/cmd/merge.go index 9ea736ae..084b6ebb 100644 --- a/cmd/merge.go +++ b/cmd/merge.go @@ -1,10 +1,11 @@ package cmd import ( + "strings" + "github.com/mikefarah/yq/v3/pkg/yqlib" errors "github.com/pkg/errors" "github.com/spf13/cobra" - "strings" ) func createMergeCmd() *cobra.Command { diff --git a/cmd/root.go b/cmd/root.go index ca1c5264..84e4703b 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -1,9 +1,10 @@ package cmd import ( + "os" + "github.com/spf13/cobra" logging "gopkg.in/op/go-logging.v1" - "os" ) func New() *cobra.Command { diff --git a/cmd/utils.go b/cmd/utils.go index eb7b7531..ebe83f5b 100644 --- a/cmd/utils.go +++ b/cmd/utils.go @@ -3,14 +3,15 @@ package cmd import ( "bufio" "fmt" - "github.com/mikefarah/yq/v3/pkg/yqlib" - errors "github.com/pkg/errors" - "github.com/spf13/cobra" - yaml "gopkg.in/yaml.v3" "io" "io/ioutil" "os" "strconv" + + "github.com/mikefarah/yq/v3/pkg/yqlib" + errors "github.com/pkg/errors" + "github.com/spf13/cobra" + yaml "gopkg.in/yaml.v3" ) func readYamlFile(filename string, path string, updateAll bool, docIndexInt int) ([]*yqlib.NodeContext, error) { diff --git a/pkg/yqlib/value_parser.go b/pkg/yqlib/value_parser.go index 6f145a75..e76138ce 100644 --- a/pkg/yqlib/value_parser.go +++ b/pkg/yqlib/value_parser.go @@ -1,8 +1,6 @@ package yqlib import ( - "strconv" - yaml "gopkg.in/yaml.v3" ) @@ -18,30 +16,8 @@ func NewValueParser() ValueParser { } func (v *valueParser) Parse(argument string, customTag string) *yaml.Node { - var err interface{} - var tag = customTag - - if tag == "" { - _, err = strconv.ParseBool(argument) - if err == nil { - tag = "!!bool" - } - _, err = strconv.ParseFloat(argument, 64) - if err == nil { - tag = "!!float" - } - _, err = strconv.ParseInt(argument, 10, 64) - if err == nil { - tag = "!!int" - } - - if argument == "null" { - tag = "!!null" - } - if argument == "[]" { - return &yaml.Node{Tag: "!!seq", Kind: yaml.SequenceNode} - } + if argument == "[]" { + return &yaml.Node{Tag: "!!seq", Kind: yaml.SequenceNode} } - log.Debugf("parsed value '%v', tag: '%v'", argument, tag) - return &yaml.Node{Value: argument, Tag: tag, Kind: yaml.ScalarNode} + return &yaml.Node{Value: argument, Tag: customTag, Kind: yaml.ScalarNode} } diff --git a/pkg/yqlib/value_parser_test.go b/pkg/yqlib/value_parser_test.go index fb439d69..df1c4c9d 100644 --- a/pkg/yqlib/value_parser_test.go +++ b/pkg/yqlib/value_parser_test.go @@ -13,13 +13,9 @@ var parseValueTests = []struct { expectedTag string testDescription string }{ - {"true", "", "!!bool", "boolean"}, {"true", "!!str", "!!str", "boolean forced as string"}, - {"3.4", "", "!!float", "float"}, - {"1212121", "", "!!int", "big number"}, - {"1212121.1", "", "!!float", "big float number"}, - {"3", "", "!!int", "int"}, - {"null", "", "!!null", "null"}, + {"3", "!!int", "!!int", "int"}, + {"cat", "", "", "default"}, } func TestValueParserParse(t *testing.T) { diff --git a/yq.go b/yq.go index ef17961a..fcfe4e54 100644 --- a/yq.go +++ b/yq.go @@ -1,9 +1,10 @@ package main import ( + "os" + command "github.com/mikefarah/yq/v3/cmd" logging "gopkg.in/op/go-logging.v1" - "os" ) func main() {