package main import ( yaml "github.com/goccy/go-yaml" "github.com/spf13/cobra" ) var VERBOSITY = 3 var SYMMETRIC_DIFF = false type TypeId int const ( Map TypeId = iota Slice Scalar ) func Type(elem any) TypeId { switch elem.(type) { case yaml.MapSlice: return Map case []any: return Slice default: return Scalar } } func main() { cmd := &cobra.Command{ Use: "yamltool", Short: "Shows one-way difference between yaml files", Long: ` Shows the changes in compared to `, } diff := &cobra.Command{ Use: "diff [file1] [file2]", Short: "Shows one-way difference between yaml files", Long: ` Shows the additions and modifications in compared to `, RunE: func(cmd *cobra.Command, args []string) error { return diff(cmd, args) }, } cmd.AddCommand(diff) merge := &cobra.Command{ Use: "merge [file1] ... [fileN]", Short: "Merge yaml files.", Long: `Changes will be merged into the first file, so later files override earlier ones`, RunE: func(cmd *cobra.Command, args []string) error { return merge(cmd, args) }, } cmd.AddCommand(merge) diff.PersistentFlags().IntVarP(&VERBOSITY, "array-output-level", "v", 3, `Array output level: , 0: no output, only exit status, 1: only show changed/added values, 2: show identical as , 3: show all values`) diff.Flags().BoolVarP(&SYMMETRIC_DIFF, "symmetric-diff", "s", false, `Symmetric difference, compare in both directions`) cmd.Execute() }