mirror of
https://github.com/mikefarah/yq.git
synced 2025-01-12 19:25:37 +00:00
Removed custom value parsing logic
This commit is contained in:
parent
8a65822b0b
commit
1a4d8158ba
@ -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 {
|
||||
|
@ -1,9 +1,10 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
logging "gopkg.in/op/go-logging.v1"
|
||||
"os"
|
||||
)
|
||||
|
||||
func New() *cobra.Command {
|
||||
|
@ -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) {
|
||||
|
@ -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}
|
||||
}
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user