forked from extern/httpie-cli
Merge pull request #16 from tictactix/master
Added a way to force pretty printing
This commit is contained in:
commit
d02ac54130
@ -70,7 +70,8 @@ parser.add_argument('--style', '-s', dest='style', default='solarized', metavar=
|
|||||||
choices=pretty.AVAILABLE_STYLES,
|
choices=pretty.AVAILABLE_STYLES,
|
||||||
help='Output coloring style, one of %s. Defaults to solarized.'
|
help='Output coloring style, one of %s. Defaults to solarized.'
|
||||||
% ', '.join(sorted(pretty.AVAILABLE_STYLES)))
|
% ', '.join(sorted(pretty.AVAILABLE_STYLES)))
|
||||||
|
parser.add_argument('--pretty', '-p', help='Force pretty print.',
|
||||||
|
dest='force_pretty', action='store_true', default=False)
|
||||||
|
|
||||||
# ``requests.request`` keyword arguments.
|
# ``requests.request`` keyword arguments.
|
||||||
parser.add_argument('--auth', '-a', help='username:password',
|
parser.add_argument('--auth', '-a', help='username:password',
|
||||||
@ -113,6 +114,7 @@ def main(args=None,
|
|||||||
stdout_isatty=sys.stdout.isatty()):
|
stdout_isatty=sys.stdout.isatty()):
|
||||||
|
|
||||||
args = parser.parse_args(args if args is not None else sys.argv[1:])
|
args = parser.parse_args(args if args is not None else sys.argv[1:])
|
||||||
|
is_pretty = args.force_pretty or stdout_isatty
|
||||||
|
|
||||||
# Parse request headers and data from the command line.
|
# Parse request headers and data from the command line.
|
||||||
headers = CaseInsensitiveDict()
|
headers = CaseInsensitiveDict()
|
||||||
@ -175,7 +177,7 @@ def main(args=None,
|
|||||||
response.content.decode(encoding) if response.content else u''
|
response.content.decode(encoding) if response.content else u''
|
||||||
)
|
)
|
||||||
|
|
||||||
if args.prettify and stdout_isatty:
|
if args.prettify and is_pretty:
|
||||||
prettify = pretty.PrettyHttp(args.style)
|
prettify = pretty.PrettyHttp(args.style)
|
||||||
if args.print_headers:
|
if args.print_headers:
|
||||||
status_line = prettify.headers(status_line).strip()
|
status_line = prettify.headers(status_line).strip()
|
||||||
|
Loading…
Reference in New Issue
Block a user