MCPcopy Create free account
hub / github.com/cli/cli / jsonFieldsFor

Function jsonFieldsFor

pkg/jsonfieldstest/jsonfieldstest.go:13–27  ·  view source on GitHub ↗
(cmd *cobra.Command)

Source from the content-addressed store, hash-verified

11)
12
13func jsonFieldsFor(cmd *cobra.Command) []string {
14 // This annotation is added by the `cmdutil.AddJSONFlags` function.
15 //
16 // This is an extremely janky way to get access to this information but due to the fact we pass
17 // around concrete cobra.Command structs, there's no viable way to have typed access to the fields.
18 //
19 // It's also kind of fragile because it's several hops away from the code that actually validates the usage
20 // of these flags, so it's possible for things to get out of sync.
21 stringFields, ok := cmd.Annotations["help:json-fields"]
22 if !ok {
23 return nil
24 }
25
26 return strings.Split(stringFields, ",")
27}
28
29// NewCmdFunc represents the typical function signature we use for creating commands e.g. `NewCmdView`.
30//

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected