1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
|
package cli
import (
"fmt"
"time"
)
// Workaround for https://github.com/go-yaml/yaml/issues/139
func normalizeYAML(v any) any {
switch v := v.(type) {
case map[any]any:
w := make(map[string]any, len(v))
for k, v := range v {
w[fmt.Sprint(k)] = normalizeYAML(v)
}
return w
case map[string]any:
w := make(map[string]any, len(v))
for k, v := range v {
w[k] = normalizeYAML(v)
}
return w
case []any:
for i, w := range v {
v[i] = normalizeYAML(w)
}
return v
// go-yaml unmarshals timestamp string to time.Time but gojq cannot handle it.
// It is impossible to keep the original timestamp strings.
case time.Time:
return v.Format(time.RFC3339)
default:
return v
}
}
|