MCPcopy
hub / github.com/cli/cli / checkFormatFlags

Function checkFormatFlags

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

Source from the content-addressed store, hash-verified

172}
173
174func checkFormatFlags(cmd *cobra.Command) (*jsonExporter, error) {
175 f := cmd.Flags()
176 formatFlag := f.Lookup("format")
177 formatValue := formatFlag.Value.String()
178 jqFlag := f.Lookup("jq")
179 tplFlag := f.Lookup("template")
180 webFlag := f.Lookup("web")
181
182 if formatFlag.Changed {
183 if webFlag != nil && webFlag.Changed {
184 return nil, errors.New("cannot use `--web` with `--format`")
185 }
186 return &jsonExporter{
187 filter: jqFlag.Value.String(),
188 template: tplFlag.Value.String(),
189 }, nil
190 } else if jqFlag.Changed && formatValue != "json" {
191 return nil, errors.New("cannot use `--jq` without specifying `--format json`")
192 } else if tplFlag.Changed && formatValue != "json" {
193 return nil, errors.New("cannot use `--template` without specifying `--format json`")
194 }
195 return nil, nil
196}
197
198type Exporter interface {
199 Fields() []string

Callers 1

AddFormatFlagsFunction · 0.85

Calls 1

StringMethod · 0.45

Tested by

no test coverage detected