Skip to content

Incorrect error shown (the --slurp option is not supported with --jq or --template) when passing --jq + --template without --slurp #10260

@0xdevalias

Description

@0xdevalias

Describe the bug

When running the following:

⇒ gh api notifications -F participating=true --jq '.' --template '{{range .}}{{tablerow .repository.full_name (truncate 100 .subject.title) .subject.type .reason (timeago .updated_at)}}{{end}}'

I get the following error:

the `--slurp` option is not supported with `--jq` or `--template`

Even though my command doesn't include --slurp, and it only attempts to use --jq and --template together.

This was seemingly introduced in this PR:

cli/pkg/cmd/api/api.go

Lines 246 to 253 in 60f8417

if err := cmdutil.MutuallyExclusive(
"the `--slurp` option is not supported with `--jq` or `--template`",
opts.Slurp,
opts.FilterOutput != "",
opts.Template != "",
); err != nil {
return err
}

Looking closer at that code, we can see there is an error case below this that I would have expected to be shown instead:

only one of --template, --jq, --silent, or --verbose may be used

cli/pkg/cmd/api/api.go

Lines 255 to 263 in 60f8417

if err := cmdutil.MutuallyExclusive(
"only one of `--template`, `--jq`, `--silent`, or `--verbose` may be used",
opts.Verbose,
opts.Silent,
opts.FilterOutput != "",
opts.Template != "",
); err != nil {
return err
}

Steps to reproduce the behavior

See above.

Expected vs actual behavior

Ideally I would expect --jq to allow me to process the JSON, and then --template to allow me to render that processed json. I have raised a feature request for that aspect here:

If for some reason there is an actual technical limitation as to why that isn't possible, then I would at least expect the error message to accurately describe the error in what I am trying to do, and not mention a seemingly not used argument.

Logs

Paste the activity from your command line. Redact if needed.

the `--slurp` option is not supported with `--jq` or `--template`

Usage:  gh api <endpoint> [flags]

Flags:
      --cache duration        Cache the response, e.g. "3600s", "60m", "1h"
  -F, --field key=value       Add a typed parameter in key=value format
  -H, --header key:value      Add a HTTP request header in key:value format
      --hostname string       The GitHub hostname for the request (default "github.com")
  -i, --include               Include HTTP response status line and headers in the output
      --input file            The file to use as body for the HTTP request (use "-" to read from standard input)
  -q, --jq string             Query to select values from the response using jq syntax
  -X, --method string         The HTTP method for the request (default "GET")
      --paginate              Make additional HTTP requests to fetch all pages of results
  -p, --preview names         GitHub API preview names to request (without the "-preview" suffix)
  -f, --raw-field key=value   Add a string parameter in key=value format
      --silent                Do not print the response body
      --slurp                 Use with "--paginate" to return an array of all pages of either JSON arrays or objects
  -t, --template string       Format JSON output using a Go template; see "gh help formatting"
      --verbose               Include full HTTP request and response in the output

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggh-apirelating to the gh api commandhelp wantedContributions welcomep3Affects a small number of users or is largely cosmetic

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions