func runSetBodyCmd()

in cli/image_cmds.go [593:627]


func runSetBodyCmd(cmd *cobra.Command, args []string) {
	if len(args) < 2 {
		ImgmodUsage(cmd, nil)
	}

	imgFilename := args[0]
	bodyFilename := args[1]

	if bodyFilename == "" {
		ImgmodUsage(cmd, errors.Errorf("image body required"))
	}
	bodyBytes, err := ioutil.ReadFile(bodyFilename)
	if err != nil {
		ImgmodUsage(cmd, errors.Wrapf(err, "error reading image body file"))
	}

	outFilename, err := CalcOutFilename(imgFilename)
	if err != nil {
		ImgmodUsage(cmd, err)
	}

	img, err := readImage(imgFilename)
	if err != nil {
		ImgmodUsage(cmd, err)
	}

	img, err = iimg.ReplaceBody(img, bodyBytes)
	if err != nil {
		ImgmodUsage(nil, err)
	}

	if err := writeImage(img, outFilename); err != nil {
		ImgmodUsage(nil, err)
	}
}