From 506378cc21e648f70a8a5f7ab7dd331dc57e8b2f Mon Sep 17 00:00:00 2001 From: "Babak K. Shandiz" Date: Mon, 6 May 2024 17:54:59 +0100 Subject: [PATCH] Add `help:json-fields` annotation Signed-off-by: Babak K. Shandiz --- pkg/cmdutil/json_flags.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/pkg/cmdutil/json_flags.go b/pkg/cmdutil/json_flags.go index bc3c242fe..440e0e0b8 100644 --- a/pkg/cmdutil/json_flags.go +++ b/pkg/cmdutil/json_flags.go @@ -83,6 +83,15 @@ func AddJSONFlags(cmd *cobra.Command, exportTarget *Exporter, fields []string) { } return e }) + + if len(fields) == 0 { + return + } + + if cmd.Annotations == nil { + cmd.Annotations = map[string]string{} + } + cmd.Annotations["help:json-fields"] = strings.Join(fields, ",") } func checkJSONFlags(cmd *cobra.Command) (*jsonExporter, error) {