Skip to content

Improve gh api short flag output to mention @ support #9966

Description

@jsoref

Describe the feature or problem you’d like to solve

I'm trying to submit a ~200KB SARIF file to the upload SARIF endpoint.

Using gh involves constructing the entire payload as a command-line, and shells don't really approve of 200KB command-lines...

Proposed solution

Add some syntax to allow passing data via a file instead of expanded on a command line will allow users to use gh to submit large SARIF files (and probably other payloads) instead of resorting to curl.

(check-spelling is currently on the fence and uses gh some of the time and curl some of the time.)

Additional context

Trying to use gh fails miserably:
https://github.com/check-spelling-sandbox/terminal/actions/runs/12045375307/job/33583882502#step:2:14473

/home/runner/work/_temp/ed03237b-484a-4109-85ed-e2c9b2bc52a4.sh: line 11: /usr/bin/gh: Argument list too long

Using curl works:
https://github.com/check-spelling-sandbox/terminal/actions/runs/12046644392/job/33587535642#step:2:13835

curl -s -L
-X POST
-H "Accept: application/vnd.github+json"
-H "Authorization: ***"
-H "X-GitHub-Api-Version: 2022-11-28"
"$GITHUB_API_URL/repos/$GITHUB_REPOSITORY/code-scanning/sarifs"
-d @"$sarif_payload" -o "$result"

Activity

  1. williammartin commented on Nov 29, 2024

    @williammartin
    Member

    Hey @jsoref,

    Is the --input flag insufficient for your use case?

    --input file            The file to use as body for the HTTP request (use "-" to read from standard input)
    

    I'm honestly not sure how it interacts with -f, but based on your curl I'm also not sure if you need it? Happy to spend time doing further investigation if it is something you need.

    Cheers.

  2. jsoref commented on Nov 29, 2024

    @jsoref
    ContributorAuthor

    I couldn't tell. If it works, it needs to be documented in the -f documentation.

  3. williammartin commented on Nov 29, 2024

    @williammartin
    Member

    I couldn't tell. If it works, it needs to be documented in the -f documentation.

    Actually it looks like it's covered in the Long description:

    To pass pre-constructed JSON or payloads in other formats, a request body may be read
    from file specified by --input. Use - to read from standard input. When passing the
    request body this way, any parameters specified via field flags are added to the query
    string of the endpoint URL.

  4. williammartin commented on Nov 29, 2024

    @williammartin
    Member

    And in fact, in the -F/--field flag part in the long description it says:

    if the value starts with @, the rest of the value is interpreted as a
    filename to read the value from. Pass - to read from standard input.

    Which I had no idea about!

    This looks like it satisfies the same feature as curl right?

  5. changed the title [-]Provide an equivalent to `curl`'s `-d @filename` for at least `gh api`[/-] [+]Improve `gh api` short flag output to mention `@` support[/+] on Nov 29, 2024
  6. jsoref commented on Nov 29, 2024

    @jsoref
    ContributorAuthor

    Hmm, it sounds like the feature is indeed there. I'd argue that the @ stuff should be hinted in the summary just as - is for -i:

      -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)
    
  7. self-assigned this
    on Oct 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementa request to improve CLIgh-apirelating to the gh api commandmore-info-neededMore info needed from user/contributorneeds-triageneeds to be reviewed

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions