Removed custom value parsing logic

This commit is contained in:
Mike Farah 2020-01-20 08:42:08 +11:00
parent 8a65822b0b
commit 1a4d8158ba
6 changed files with 16 additions and 40 deletions

View File

@ -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 {

View File

@ -1,9 +1,10 @@
package cmd
import (
"os"
"github.com/spf13/cobra"
logging "gopkg.in/op/go-logging.v1"
"os"
)
func New() *cobra.Command {

View File

@ -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) {

View File

@ -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}
}

View File

@ -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) {

3
yq.go
View File

@ -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() {