From dabc1c726393e470f103080f81b6ad7021be2fd6 Mon Sep 17 00:00:00 2001 From: Chenyang Liu Date: Thu, 29 Feb 2024 15:44:41 -0500 Subject: [PATCH] Feature/output file CLI option --- awscurl/awscurl.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/awscurl/awscurl.py b/awscurl/awscurl.py index b9ed9dc..abc570e 100755 --- a/awscurl/awscurl.py +++ b/awscurl/awscurl.py @@ -472,6 +472,7 @@ def inner_main(argv): parser.add_argument('--session_token', env_var='AWS_SESSION_TOKEN') parser.add_argument('-L', '--location', action='store_true', default=False, help="Follow redirects") + parser.add_argument('-o', '--output', metavar="", help='Write to file instead of stdout', default='') parser.add_argument('uri') @@ -535,6 +536,12 @@ def inner_main(argv): print(response.text) + if args.output: + filename = args.output + file_mode = "wb" if args.data_binary else "w" + with open(filename, file_mode) as f: + f.write(response.content) + exit_code = 0 if response.ok else 1 return exit_code