Exemplo n.º 1
0
func processArg(arg string, obj interface{}) {
	if strings.HasPrefix(arg, "--") {
		keyval := arg[2:]
		tokens := strings.SplitN(keyval, "=", 2)
		if len(tokens) != 2 {
			fmt.Fprintf(os.Stderr, "value for %q must be in the form of %q\n", arg, arg+"=VALUE")
			os.Exit(1)
		}
		key, val := tokens[0], tokens[1]
		orExit(overwrite.Overwrite(obj, key, val))
		return
	}
	if strings.HasSuffix(strings.ToLower(arg), ".json") {
		fin, err := os.Open(arg)
		orExit(err)
		orExit(json.NewDecoder(fin).Decode(obj))
		return
	}
	if strings.HasSuffix(strings.ToLower(arg), ".yaml") {
		fin, err := os.Open(arg)
		orExit(err)
		data, err := ioutil.ReadAll(fin)
		orExit(err)
		orExit(yaml.Unmarshal(data, obj))
		return
	}
	if strings.HasSuffix(strings.ToLower(arg), ".rjson") {
		fin, err := os.Open(arg)
		orExit(err)
		orExit(rjson.NewDecoder(fin).Decode(obj))
		return
	}
	fmt.Fprintf(os.Stderr, "don't know what to do with %q\n", arg)
	os.Exit(1)
}
Exemplo n.º 2
0
func OverwriteRequestWithValues(requestObject interface{}, keyValues map[string]string) error {
	for key, val := range keyValues {
		err := overwrite.Overwrite(requestObject, key, val)
		if err != nil {
			return fmt.Errorf("for key \"--%s\" while evaluating %s: %s", key, val, err)
		}
	}
	return nil
}