(cmd *cobra.Command)
| 172 | } |
| 173 | |
| 174 | func 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 | |
| 198 | type Exporter interface { |
| 199 | Fields() []string |
no test coverage detected