gh コマンドでページャーを使いたかった
$ gh api '/users/atm-snag2/repos' -q '.[].name'
activerecord-mysql-sql-cache
arproxy
clsss_nest_remover
gratan
homebrew-core
ruboty-slack_events
ruboty-slack_rtm
typescript-study
yard-examples
per_page = 3 とか指定したかった
$ gh api -h
-F, --field key=value Add a typed parameter in key=value format
-f, --raw-field key=value Add a string parameter in key=value format
Pass one or more `-f/--raw-field` values in `key=value` format to add static string
parameters to the request payload. To add non-string or placeholder-determined values, see
`-F/--field` below. Note that adding request parameters will automatically switch the
request method to `POST`. To send the parameters as a `GET` query string instead, use
`--method GET`.
API ドキュメントにクエリパラメータと書いてあった.
-F/-f は,payload に指定するらしかった
なので,これだと駄目
$ gh api '/users/atm-snag2/repos' -q '.[].name' -f 'per_page=3'
{
"message": "Not Found",
"documentation_url": "https://docs.github.com/rest",
"status": "404"
}
gh: Not Found (HTTP 404)
できる
$ gh api '/users/atm-snag2/repos?per_page=3' -q '.[].name'
activerecord-mysql-sql-cache
arproxy
clsss_nest_remover
そもそも
最初に考えた要件が間違っていて,全部が取れれば良かったので,--paginate
を使えばよい
$ gh api '/users/atm-snag2/repos?per_page=3' -q '.[].name' --paginate
activerecord-mysql-sql-cache
arproxy
clsss_nest_remover
gratan
homebrew-core
ruboty-slack_events
ruboty-slack_rtm
typescript-study
yard-examples
Refs
クエリ パラメーター
per_page integer
The number of results per page (max 100). For more information, see "Using pagination in the REST API."
Default: 30
In --paginate mode, all pages of results will sequentially be requested until there are no more pages of results. For GraphQL requests, this requires that the original query accepts an $endCursor: String variable and that it fetches the pageInfo{ hasNextPage, endCursor } set of fields from a collection. Each page is a separate JSON array or object. Pass --slurp to wrap all pages of JSON arrays or objects into an outer JSON array.