mirror of
https://github.com/mikefarah/yq.git
synced 2025-01-13 03:45:37 +00:00
Removed custom value parsing logic
This commit is contained in:
parent
8a65822b0b
commit
1a4d8158ba
@ -1,10 +1,11 @@
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/mikefarah/yq/v3/pkg/yqlib"
|
"github.com/mikefarah/yq/v3/pkg/yqlib"
|
||||||
errors "github.com/pkg/errors"
|
errors "github.com/pkg/errors"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"strings"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func createMergeCmd() *cobra.Command {
|
func createMergeCmd() *cobra.Command {
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"os"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
logging "gopkg.in/op/go-logging.v1"
|
logging "gopkg.in/op/go-logging.v1"
|
||||||
"os"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func New() *cobra.Command {
|
func New() *cobra.Command {
|
||||||
|
@ -3,14 +3,15 @@ package cmd
|
|||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/mikefarah/yq/v3/pkg/yqlib"
|
|
||||||
errors "github.com/pkg/errors"
|
|
||||||
"github.com/spf13/cobra"
|
|
||||||
yaml "gopkg.in/yaml.v3"
|
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
"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) {
|
func readYamlFile(filename string, path string, updateAll bool, docIndexInt int) ([]*yqlib.NodeContext, error) {
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
package yqlib
|
package yqlib
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strconv"
|
|
||||||
|
|
||||||
yaml "gopkg.in/yaml.v3"
|
yaml "gopkg.in/yaml.v3"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -18,30 +16,8 @@ func NewValueParser() ValueParser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (v *valueParser) Parse(argument string, customTag string) *yaml.Node {
|
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 == "[]" {
|
if argument == "[]" {
|
||||||
return &yaml.Node{Tag: "!!seq", Kind: yaml.SequenceNode}
|
return &yaml.Node{Tag: "!!seq", Kind: yaml.SequenceNode}
|
||||||
}
|
}
|
||||||
}
|
return &yaml.Node{Value: argument, Tag: customTag, Kind: yaml.ScalarNode}
|
||||||
log.Debugf("parsed value '%v', tag: '%v'", argument, tag)
|
|
||||||
return &yaml.Node{Value: argument, Tag: tag, Kind: yaml.ScalarNode}
|
|
||||||
}
|
}
|
||||||
|
@ -13,13 +13,9 @@ var parseValueTests = []struct {
|
|||||||
expectedTag string
|
expectedTag string
|
||||||
testDescription string
|
testDescription string
|
||||||
}{
|
}{
|
||||||
{"true", "", "!!bool", "boolean"},
|
|
||||||
{"true", "!!str", "!!str", "boolean forced as string"},
|
{"true", "!!str", "!!str", "boolean forced as string"},
|
||||||
{"3.4", "", "!!float", "float"},
|
{"3", "!!int", "!!int", "int"},
|
||||||
{"1212121", "", "!!int", "big number"},
|
{"cat", "", "", "default"},
|
||||||
{"1212121.1", "", "!!float", "big float number"},
|
|
||||||
{"3", "", "!!int", "int"},
|
|
||||||
{"null", "", "!!null", "null"},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestValueParserParse(t *testing.T) {
|
func TestValueParserParse(t *testing.T) {
|
||||||
|
Loading…
Reference in New Issue
Block a user