Skip to content

Commit

Permalink
Feature/output file CLI option
Browse files Browse the repository at this point in the history
  • Loading branch information
chenliu0831 committed Feb 29, 2024
1 parent 2b9f163 commit dabc1c7
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions awscurl/awscurl.py
Original file line number Diff line number Diff line change
Expand Up @@ -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="<file>", help='Write to file instead of stdout', default='')

parser.add_argument('uri')

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit dabc1c7

Please sign in to comment.