Skip to content

Commit

Permalink
support yaml output
Browse files Browse the repository at this point in the history
  • Loading branch information
keisku committed Aug 7, 2021
1 parent 5ce9e76 commit 1db2615
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions find.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ func run(ctx context.Context, name string, opt options) error {
secrets = append(secrets, s)
}
}
return printSecrets(secrets)
return printSecrets(secrets, opt.Output)
}
return printSecrets(ss)
return printSecrets(ss, opt.Output)
}

func findSecrets(ctx context.Context, name string, opt options) ([]v1.Secret, error) {
Expand Down Expand Up @@ -132,7 +132,7 @@ func getAllNamespaces(ctx context.Context) ([]v1.Namespace, error) {
return nl.Items, nil
}

func printSecrets(ss []v1.Secret) error {
func printSecrets(ss []v1.Secret, output string) error {
m := make(map[string][]interface{}, len(ss))
for _, s := range ss {
data := make(map[string]string)
Expand All @@ -143,9 +143,19 @@ func printSecrets(ss []v1.Secret) error {
s.Name: data,
})
}
b, err := json.MarshalIndent(m, "", " ")
if err != nil {
return err
var b []byte
var err error
switch output {
case "json":
b, err = json.MarshalIndent(m, "", " ")
if err != nil {
return err
}
case "yaml":
b, err = yaml.Marshal(m)
if err != nil {
return err
}
}
fmt.Printf("%s\n", string(b))
return nil
Expand Down

0 comments on commit 1db2615

Please sign in to comment.