Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@AliabbasMerchant
Copy link
Contributor

Summary

closes #1188

@AliabbasMerchant AliabbasMerchant changed the title --silent flag in api Support for --silent flag in api Jun 28, 2020
Copy link
Contributor

@mislav mislav left a 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
Copy link
Contributor

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?

Copy link
Contributor

@mislav mislav Jun 30, 2020

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!

Copy link
Contributor Author

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.


func processResponse(resp *http.Response, opts *ApiOptions) (endCursor string, err error) {
if opts.ShowResponseHeaders {
if opts.ShowResponseHeaders && !opts.Silent {
Copy link
Contributor

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.

Copy link
Contributor Author

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.

assert.Equal(t, "PAGE1_END", endCursor)
}

func Test_apiRun_silent(t *testing.T) {
Copy link
Contributor

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?

Copy link
Contributor Author

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!

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")
Copy link
Contributor

@mislav mislav Jun 30, 2020

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
@AliabbasMerchant AliabbasMerchant requested a review from mislav June 30, 2020 13:57
Copy link
Contributor

@mislav mislav left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fantastic; thank you!

Copy link
Contributor

@vilmibm vilmibm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks!

@mislav mislav merged commit 7eeeed9 into cli:trunk Jul 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

api command: provide flag to silence output

3 participants