forked from extern/httpie-cli
Added a quiet functionality
This commit is contained in:
parent
ebf2139fd5
commit
a4a1e8d43b
@ -135,10 +135,16 @@ class HTTPieArgumentParser(argparse.ArgumentParser):
|
||||
Modify `env.stdout` and `env.stdout_isatty` based on args, if needed.
|
||||
|
||||
"""
|
||||
if self.args.quiet:
|
||||
self.env.stdout = self.env.devnull
|
||||
self.env.stdout_isatty = self.env.devnull_isatty
|
||||
self.env.stderr = self.env.devnull
|
||||
self.env.stderr_isatty = self.env.devnull_isatty
|
||||
|
||||
self.args.output_file_specified = bool(self.args.output_file)
|
||||
if self.args.download:
|
||||
# FIXME: Come up with a cleaner solution.
|
||||
if not self.args.output_file and not self.env.stdout_isatty:
|
||||
if not self.args.output_file and not self.env.stdout_isatty and not self.args.quiet:
|
||||
# Use stdout as the download output file.
|
||||
self.args.output_file = self.env.stdout
|
||||
# With `--download`, we write everything that would normally go to
|
||||
|
@ -426,6 +426,16 @@ output_options.add_argument(
|
||||
'''
|
||||
)
|
||||
|
||||
output_options.add_argument(
|
||||
'--quiet', '-q',
|
||||
action='store_true',
|
||||
default=False,
|
||||
help='''
|
||||
Do not print to stdout or stderr.
|
||||
|
||||
'''
|
||||
)
|
||||
|
||||
#######################################################################
|
||||
# Sessions
|
||||
#######################################################################
|
||||
|
@ -1,4 +1,5 @@
|
||||
import sys
|
||||
import os
|
||||
from pathlib import Path
|
||||
from typing import IO, Optional
|
||||
|
||||
@ -34,6 +35,8 @@ class Environment:
|
||||
stdout_encoding: str = None
|
||||
stderr: IO = sys.stderr
|
||||
stderr_isatty: bool = stderr.isatty()
|
||||
devnull: IO = open(os.devnull, "w")
|
||||
devnull_isatty: bool = devnull.isatty()
|
||||
colors = 256
|
||||
program_name: str = 'http'
|
||||
if not is_windows:
|
||||
@ -45,7 +48,7 @@ class Environment:
|
||||
pass
|
||||
else:
|
||||
# noinspection PyUnresolvedReferences
|
||||
import colorama.initialise
|
||||
import colorama.initialisex
|
||||
stdout = colorama.initialise.wrap_stream(
|
||||
stdout, convert=None, strip=None,
|
||||
autoreset=True, wrap=True
|
||||
|
Loading…
Reference in New Issue
Block a user