Skip to content

Commit fdf72b8

Browse files
fix: validate --format flag and use cobra output writer
Signed-off-by: Rahul Vishwakarma <rahulvs2809@gmail.com>
1 parent 88c5569 commit fdf72b8

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

cmd/archivistactl/cmd/search.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ Digests are expected to be in the form algorithm:digest, for instance: sha256:45
4444
return nil
4545
},
4646
RunE: func(cmd *cobra.Command, args []string) error {
47+
if format != "table" && format != "json" {
48+
return fmt.Errorf("unsupported format %q: supported formats are table, json", format)
49+
}
50+
4751
algo, digest, err := validateDigestString(args[0])
4852
if err != nil {
4953
return err
@@ -59,7 +63,7 @@ Digests are expected to be in the form algorithm:digest, for instance: sha256:45
5963
if err != nil {
6064
return fmt.Errorf("failed to marshal results to JSON: %w", err)
6165
}
62-
fmt.Println(string(jsonData))
66+
cmd.Println(string(jsonData))
6367
return nil
6468
}
6569

0 commit comments

Comments
 (0)