-
Notifications
You must be signed in to change notification settings - Fork 7.3k
Support for --silent flag in api #1283
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's great that you're tackling this; thank you! I have a few asks π
| } | ||
|
|
||
| if opts.Silent { | ||
| opts.IO.Out = ioutil.Discard |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a neat trick! But, since parsing response JSON will take some processing time and will ultimately be discarded, could you instead skip the body processing logic in "silent" mode and exit from the command early?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On the other hand, I just realized that the response body needs to be first consumed in order for our response error processing logic to work. So, maybe discard my above comment please, as following my suggestion might lead to too many code changes. I'll leave it to you!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this Discard option is better than some complex logic. I agree with you on the error handling part. Even if I put the custom logic and all, it will become too bloated, and will cause problems down the line also, in case we need to add/change some feature/working.
pkg/cmd/api/api.go
Outdated
|
|
||
| func processResponse(resp *http.Response, opts *ApiOptions) (endCursor string, err error) { | ||
| if opts.ShowResponseHeaders { | ||
| if opts.ShowResponseHeaders && !opts.Silent { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need to change this conditional. In fact, if someone requested response headers, let's display them even in --silent mode. Maybe there is some use-case for that, and I think it's safe to allow because both -i and --silent flags are explicitly opt-in.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right. Makes sense. I will remove that.
pkg/cmd/api/api_test.go
Outdated
| assert.Equal(t, "PAGE1_END", endCursor) | ||
| } | ||
|
|
||
| func Test_apiRun_silent(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of adding a separate test function, could you add the Silent: true mode as another test case in Test_apiRun please?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh. Right. I will do that!
pkg/cmd/api/api.go
Outdated
| cmd.Flags().BoolVarP(&opts.ShowResponseHeaders, "include", "i", false, "Include HTTP response headers in the output") | ||
| cmd.Flags().BoolVar(&opts.Paginate, "paginate", false, "Make additional HTTP requests to fetch all pages of results") | ||
| cmd.Flags().StringVar(&opts.RequestInputFile, "input", "", "The file to use as body for the HTTP request") | ||
| cmd.Flags().BoolVar(&opts.Silent, "silent", false, "Silence the output") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's try to be more descriptive here: how does βDo not print response body" sound? The goal would be to describe what "silence" means in this case, since the word could be ambiguous
Show Response Headers (if requested) even with `--silent` flag Shift silent tests to `Test_apiRun` Changed usage string of `--silent` flag
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fantastic; thank you!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks!
Summary
closes #1188