Conversation
vilmibm
left a comment
There was a problem hiding this comment.
gojq? this...is awesome. 👍 , will re-review once tests are in
|
Now with documentation and tests, this is ready for full review. Final question: I can see this flag being used a lot, so I'm wondering whether |
vilmibm
left a comment
There was a problem hiding this comment.
I like this 👍
some minor requests:
- a golden path test that ensures the flag can be passed to the command and that output is formatted as expected. I know it might sound silly, but a Flags invocation could be lost in a refactor or similar so I think such simple tests have merit.
- going ahead with the
-jshortcut. I'm actually wondering if the longform should just be--jqbut I like that--filterexpresses intent more clearly. If-fwasn't already taken I'd say just do that but-jis a suitable backup.
pkg/cmd/api/api.go
Outdated
| cmd.Flags().StringVar(&opts.RequestInputFile, "input", "", "The `file` to use as body for the HTTP request") | ||
| cmd.Flags().BoolVar(&opts.Silent, "silent", false, "Do not print the response body") | ||
| cmd.Flags().StringVarP(&opts.Template, "template", "t", "", "Format the response using a Go template") | ||
| cmd.Flags().StringVar(&opts.FilterOutput, "filter", "", "Filter fields from the response using jq syntax") |
There was a problem hiding this comment.
Since filter and template are mutually exclusive I think we should probably raise an error message when both are provided.
samcoe
left a comment
There was a problem hiding this comment.
Between adding this and the templating functionality I am starting to think we should make more detailed documentation on the website for the api command. It is just such a powerful command with a ton of functionality that could use some thorough examples and structured explanation.
|
Renamed the flag |
--filter to api command to filter data using jq syntax--jq to api command to filter data using jq syntax
The
--filterflag takes a filter expression in jq syntax to select specific fields from the JSON data received from the server.Example:
This is equivalent to doing
gh api ... | jq -r '.items[].full_name', except that it's completely contained within gh and doesn't require thejqtool to be separately installed and available in the user's environment.TODO: