cmd

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 5, 2021 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var MergeCmd = &cobra.Command{
	Use:   "merge",
	Short: "merge multiple json file into one",
	Long:  "merge multiple json files into one.",
	RunE: func(cmd *cobra.Command, args []string) error {
		readConfig()

		for _, merge := range cfg.Merges {
			for _, target := range merge.Targets {

				basePath := helper.CleanJoinPath(cfg.Base, target)
				if !filepath.IsAbs(cfg.Base) {
					basePath = helper.CleanJoinPath(filepath.Dir(configFile), basePath)
				}
				base, err := helper.ReadFile(basePath)
				if err != nil {
					return err
				}

				overlayPath := helper.CleanJoinPath(filepath.Dir(configFile), target)
				overlay, err := helper.ReadFile(overlayPath)
				if err != nil {
					return err
				}

				fmt.Printf("merge: base=%s => overlay=%s\n", basePath, overlayPath)

				out, err := jmerge.MergeJSON(base, overlay, merge.Mode, cfg.Format)
				if err != nil {
					return err
				}

				outputPath := helper.CleanJoinPath(cfg.Output, cfg.Namespace, target)
				if !filepath.IsAbs(outputPath) {
					outputPath = helper.CleanJoinPath(filepath.Dir(configFile), outputPath)
				}
				if err := helper.WriteFile(filepath.Dir(outputPath), filepath.Base(outputPath), out); err != nil {
					return err
				}
			}
		}
		fmt.Printf("merge complete!\n")

		return nil
	},
}
View Source
var RootCmd = &cobra.Command{
	Use: "jmerge-cli",
	Run: func(cmd *cobra.Command, args []string) {
		cmd.Help()
	},
}

RootCmd is root command

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL