fortify: move json indent call
All checks were successful
Tests / Go tests (push) Successful in 36s
Nix / NixOS tests (push) Successful in 3m2s

Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
Ophestra 2024-12-21 18:51:59 +09:00
parent df7f692e61
commit e08c48cf3d
Signed by: cat
SSH Key Fingerprint: SHA256:gQ67O0enBZ7UdZypgtspB2FDM1g3GVw8nX0XSdcFw8Q

View File

@ -15,18 +15,15 @@ import (
func printShow(instance *state.State, config *fst.Config) { func printShow(instance *state.State, config *fst.Config) {
if flagJSON { if flagJSON {
v := interface{}(config) v := any(config)
if instance != nil { if instance != nil {
v = instance v = instance
} }
if s, err := json.MarshalIndent(v, "", " "); err != nil { printJSON(v)
fmsg.Fatalf("cannot serialise as JSON: %v", err) return
panic("unreachable")
} else {
fmt.Println(string(s))
} }
} else {
buf := new(strings.Builder) buf := new(strings.Builder)
w := tabwriter.NewWriter(buf, 0, 1, 4, ' ', 0) w := tabwriter.NewWriter(buf, 0, 1, 4, ' ', 0)
@ -140,4 +137,12 @@ func printShow(instance *state.State, config *fst.Config) {
} }
fmt.Print(buf.String()) fmt.Print(buf.String())
} }
func printJSON(v any) {
if s, err := json.MarshalIndent(v, "", " "); err != nil {
fmsg.Fatalf("cannot serialise as JSON: %v", err)
panic("unreachable")
} else {
fmt.Println(string(s))
}
} }