Httpie: Add 'quiet' or 'silent' option for using httpie in scripts

Created on 3 Jun 2020  ·  12Comments  ·  Source: httpie/httpie

Simple flag to avoid unnecessary output when using inside scripts.

contributor-friendly feature

Most helpful comment

Yes currently working on it :)

All 12 comments

Rationale: Why do many commands provide a “quiet” option?

We can handle this by replacing our env.stdout and env.stderr with os.devnull at the appropriate moment. Instead of touching os.devnull directly at runtime, though, it should be added as Environment.devnull like we do with the standard streams:

https://github.com/jakubroztocil/httpie/blob/492687b0dafb7bec0d6281d019bb5f4f60439346/httpie/context.py#L32-L35

…and from that point only reference env.devnull. This will make it possible to write good tests. So basically there should only be one conditional somewhere and all existing behavior should remain intact.

What should the flag be?

@paulolieuthier --quiet sounds pretty standard

Hey! Is someone working on this issue or can it be taken?

@nb2838 I’m not. So, unless @paulolieuthier is looking into this, it should be up for grabs.

Go ahead @nb2838! I'm looking forward to the release :)

@nb2838 Are you still working on this? I'd like to pick up this issue if not!

Yes currently working on it :)

I've been working on the problem and I think I have a working solution. My only problem thus far is that I don't know at which point precisely to close the os.devnull file. If I don't close it and let the job be done by the garbage collectore my code works fine. However, when I try closing it by adding a
finally: env.dev.null.close() at the end of main in core.py I get an error if I use --download option. I was wondering if you have any suggestions for dealing with this issue.

@nb2838 please open a PR and I’ll take a look

945 was merged and closed.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

chuma picture chuma  ·  3Comments

rashthedude picture rashthedude  ·  3Comments

rshurts picture rshurts  ·  5Comments

filipesperandio picture filipesperandio  ·  3Comments

eliangcs picture eliangcs  ·  5Comments