func _main() error {
	var data []byte
	var input []byte
	var err error
	if len(*file) > 0 {
		input, err = ioutil.ReadFile(*file)
		if err != nil {
			fmt.Println(err, "error reading the file argument given")
			os.Exit(1)
		}
	} else {
		input, err = ioutil.ReadAll(os.Stdin)
		if err != nil {
			return err
		}
	}
	if *compress {
		data, err = transform.Yaml2Json(input)
	} else {
		data, err = transform.Yaml2JsonIndent(input)
	}
	if err != nil {
		return err
	}
	_, err = os.Stdout.Write(data)
	return err
}
Beispiel #2
0
func YamlOrJson2Interface(raw []byte, isYaml, verbose bool) (*Request, error) {
	defer RecoverWithMessage("YamlOrJson2Interface", *ExitOnException, *FailureExitCode)
	var err error
	var unit *Request
	if isYaml {
		raw, err = transform.Yaml2Json(raw)
		if err != nil {
			return nil, err
		}
	}

	unit, err = Json2Request(raw)
	if err != nil {
		return nil, err
	}

	if verbose {
		version = unit.ApiVersion
		kind = unit.Kind
		Info.Printf("Raw json %v\n\n", string(raw))
		Info.Printf("Request %v\n\n", unit)
		Info.Printf("ApiVersion [%8s] Kind [%s]\n", version, kind)
	}
	return unit, nil
}