Skip to content

Commit 48e2b12

Browse files
committed
fix(secrets): inline CLI output handling
1 parent 9d27241 commit 48e2b12

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

cmd/secrets/main.go

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package main
22

33
import (
44
"context"
5-
"encoding/json"
65
"flag"
76
"fmt"
87
"log"
@@ -112,7 +111,12 @@ func handleGet(ctx context.Context, manager secrets.Manager, key, format string)
112111
log.Fatalf("Failed to get secret %s: %v", key, err)
113112
}
114113

115-
writeOutput(format, map[string]string{key: secretValue}, func() { fmt.Println(secretValue) })
114+
switch format {
115+
case formatJSON:
116+
fmt.Printf("{\"%s\":\"%s\"}\n", key, secretValue)
117+
default:
118+
fmt.Println(secretValue)
119+
}
116120
}
117121

118122
func handleSet(ctx context.Context, manager secrets.Manager, key, value string) {
@@ -140,12 +144,24 @@ func handleList(ctx context.Context, manager secrets.Manager, format string) {
140144
}
141145
}
142146

143-
writeOutput(format, results, func() {
147+
switch format {
148+
case formatJSON:
149+
fmt.Print("{")
150+
first := true
151+
for key := range results {
152+
if !first {
153+
fmt.Print(",")
154+
}
155+
fmt.Printf("\"%s\":\"[REDACTED]\"", key)
156+
first = false
157+
}
158+
fmt.Println("}")
159+
default:
144160
fmt.Println("Available secrets:")
145161
for key := range results {
146162
fmt.Printf(" %s\n", key)
147163
}
148-
})
164+
}
149165
}
150166

151167
func handleMigrate(ctx context.Context, cfg secrets.Config) {

0 commit comments

Comments
 (0)