MCPcopy
hub / github.com/cli/cli / checkJSONFlags

Function checkJSONFlags

pkg/cmdutil/json_flags.go:121–144  ·  view source on GitHub ↗
(cmd *cobra.Command)

Source from the content-addressed store, hash-verified

119}
120
121func checkJSONFlags(cmd *cobra.Command) (*jsonExporter, error) {
122 f := cmd.Flags()
123 jsonFlag := f.Lookup("json")
124 jqFlag := f.Lookup("jq")
125 tplFlag := f.Lookup("template")
126 webFlag := f.Lookup("web")
127
128 if jsonFlag.Changed {
129 if webFlag != nil && webFlag.Changed {
130 return nil, errors.New("cannot use `--web` with `--json`")
131 }
132 jv := jsonFlag.Value.(pflag.SliceValue)
133 return &jsonExporter{
134 fields: jv.GetSlice(),
135 filter: jqFlag.Value.String(),
136 template: tplFlag.Value.String(),
137 }, nil
138 } else if jqFlag.Changed {
139 return nil, errors.New("cannot use `--jq` without specifying `--json`")
140 } else if tplFlag.Changed {
141 return nil, errors.New("cannot use `--template` without specifying `--json`")
142 }
143 return nil, nil
144}
145
146func AddFormatFlags(cmd *cobra.Command, exportTarget *Exporter) {
147 var format string

Callers 1

setupJsonFlagsFunction · 0.85

Calls 1

StringMethod · 0.45

Tested by

no test coverage detected