Skip to content

Commit aab812b

Browse files
fix: validate --format flag and use cobra output writer
Address Copilot review feedback: reject unsupported --format values before making the network request instead of silently falling back to the default output, and print JSON via cmd.Println so the output respects the command's configured writer. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Signed-off-by: Rahul Vishwakarma <rahulvs2809@gmail.com>
1 parent 88c5569 commit aab812b

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)