mirror of
https://github.com/httpie/cli.git
synced 2025-05-31 23:09:49 +02:00
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.
|
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)
|
self.args.output_file_specified = bool(self.args.output_file)
|
||||||
if self.args.download:
|
if self.args.download:
|
||||||
# FIXME: Come up with a cleaner solution.
|
# 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.
|
# Use stdout as the download output file.
|
||||||
self.args.output_file = self.env.stdout
|
self.args.output_file = self.env.stdout
|
||||||
# With `--download`, we write everything that would normally go to
|
# 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
|
# Sessions
|
||||||
#######################################################################
|
#######################################################################
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import sys
|
import sys
|
||||||
|
import os
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import IO, Optional
|
from typing import IO, Optional
|
||||||
|
|
||||||
@ -34,6 +35,8 @@ class Environment:
|
|||||||
stdout_encoding: str = None
|
stdout_encoding: str = None
|
||||||
stderr: IO = sys.stderr
|
stderr: IO = sys.stderr
|
||||||
stderr_isatty: bool = stderr.isatty()
|
stderr_isatty: bool = stderr.isatty()
|
||||||
|
devnull: IO = open(os.devnull, "w")
|
||||||
|
devnull_isatty: bool = devnull.isatty()
|
||||||
colors = 256
|
colors = 256
|
||||||
program_name: str = 'http'
|
program_name: str = 'http'
|
||||||
if not is_windows:
|
if not is_windows:
|
||||||
@ -45,7 +48,7 @@ class Environment:
|
|||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
# noinspection PyUnresolvedReferences
|
# noinspection PyUnresolvedReferences
|
||||||
import colorama.initialise
|
import colorama.initialisex
|
||||||
stdout = colorama.initialise.wrap_stream(
|
stdout = colorama.initialise.wrap_stream(
|
||||||
stdout, convert=None, strip=None,
|
stdout, convert=None, strip=None,
|
||||||
autoreset=True, wrap=True
|
autoreset=True, wrap=True
|
||||||
|
Loading…
x
Reference in New Issue
Block a user