yq/cmd/compare.go

90 lines
2.9 KiB
Go
Raw Normal View History

2020-02-03 02:59:16 +00:00
package cmd
2020-10-13 01:51:37 +00:00
// import (
// "bufio"
// "bytes"
// "os"
// "strings"
2020-02-03 02:59:16 +00:00
2020-10-13 01:51:37 +00:00
// "github.com/kylelemons/godebug/diff"
// "github.com/mikefarah/yq/v3/pkg/yqlib"
// errors "github.com/pkg/errors"
// "github.com/spf13/cobra"
// )
2020-02-03 02:59:16 +00:00
2020-10-13 01:51:37 +00:00
// // turn off for unit tests :(
// var forceOsExit = true
2020-10-13 01:51:37 +00:00
// func createCompareCmd() *cobra.Command {
// var cmdCompare = &cobra.Command{
// Use: "compare [yaml_file_a] [yaml_file_b]",
// Aliases: []string{"x"},
// Short: "yq x [--prettyPrint/-P] dataA.yaml dataB.yaml 'b.e(name==fr*).value'",
// Example: `
// yq x - data2.yml # reads from stdin
// yq x -pp dataA.yaml dataB.yaml '**' # compare paths
// yq x -d1 dataA.yaml dataB.yaml 'a.b.c'
// `,
// Long: "Deeply compares two yaml files, prints the difference. Use with prettyPrint flag to ignore formatting differences.",
// RunE: compareDocuments,
// }
// cmdCompare.PersistentFlags().StringVarP(&docIndex, "doc", "d", "0", "process document index number (0 based, * for all documents)")
// cmdCompare.PersistentFlags().StringVarP(&printMode, "printMode", "p", "v", "print mode (v (values, default), p (paths), pv (path and value pairs)")
// cmdCompare.PersistentFlags().StringVarP(&defaultValue, "defaultValue", "D", "", "default value printed when there are no results")
// cmdCompare.PersistentFlags().BoolVarP(&stripComments, "stripComments", "", false, "strip comments out before comparing")
// cmdCompare.PersistentFlags().BoolVarP(&explodeAnchors, "explodeAnchors", "X", false, "explode anchors")
// return cmdCompare
// }
2020-02-03 02:59:16 +00:00
2020-10-13 01:51:37 +00:00
// func compareDocuments(cmd *cobra.Command, args []string) error {
// var path = ""
2020-02-03 03:15:12 +00:00
2020-10-13 01:51:37 +00:00
// if len(args) < 2 {
// return errors.New("Must provide at 2 yaml files")
// } else if len(args) > 2 {
// path = args[2]
// }
2020-02-03 02:59:16 +00:00
2020-10-13 01:51:37 +00:00
// var updateAll, docIndexInt, errorParsingDocIndex = parseDocumentIndex()
// if errorParsingDocIndex != nil {
// return errorParsingDocIndex
// }
2020-02-03 02:59:16 +00:00
2020-10-13 01:51:37 +00:00
// var matchingNodesA []*yqlib.NodeContext
// var matchingNodesB []*yqlib.NodeContext
// var errorDoingThings error
2020-02-03 03:15:12 +00:00
2020-10-13 01:51:37 +00:00
// matchingNodesA, errorDoingThings = readYamlFile(args[0], path, updateAll, docIndexInt)
2020-02-03 03:15:12 +00:00
2020-10-13 01:51:37 +00:00
// if errorDoingThings != nil {
// return errorDoingThings
// }
2020-02-03 02:59:16 +00:00
2020-10-13 01:51:37 +00:00
// matchingNodesB, errorDoingThings = readYamlFile(args[1], path, updateAll, docIndexInt)
// if errorDoingThings != nil {
// return errorDoingThings
// }
2020-02-03 02:59:16 +00:00
2020-10-13 01:51:37 +00:00
// var dataBufferA bytes.Buffer
// var dataBufferB bytes.Buffer
// errorDoingThings = printResults(matchingNodesA, bufio.NewWriter(&dataBufferA))
// if errorDoingThings != nil {
// return errorDoingThings
// }
// errorDoingThings = printResults(matchingNodesB, bufio.NewWriter(&dataBufferB))
// if errorDoingThings != nil {
// return errorDoingThings
// }
2020-02-03 02:59:16 +00:00
2020-10-13 01:51:37 +00:00
// diffString := diff.Diff(strings.TrimSuffix(dataBufferA.String(), "\n"), strings.TrimSuffix(dataBufferB.String(), "\n"))
2020-10-13 01:51:37 +00:00
// if len(diffString) > 1 {
// cmd.Print(diffString)
// cmd.Print("\n")
// if forceOsExit {
// os.Exit(1)
// }
// }
// return nil
// }