Commit e8bbc52d authored by Stéphane Wirtel's avatar Stéphane Wirtel Committed by Julien Palard

bpo-23596: Use argparse for the command line of gzip (GH-9781)

Co-authored-by: default avatarAntony Lee <anntzer.lee@gmail.com>
parent 84eec119
...@@ -532,18 +532,17 @@ def decompress(data): ...@@ -532,18 +532,17 @@ def decompress(data):
return f.read() return f.read()
def _test(): def main():
# Act like gzip; with -d, act like gunzip. from argparse import ArgumentParser
# The input file is not deleted, however, nor are any other gzip parser = ArgumentParser(description=
# options or features supported. "A simple command line interface for the gzip module: act like gzip, "
args = sys.argv[1:] "but do not delete the input file.")
decompress = args and args[0] == "-d" parser.add_argument("-d", "--decompress", action="store_true",
if decompress: help="act like gunzip instead of gzip")
args = args[1:] parser.add_argument("args", nargs="*", default=["-"], metavar='file')
if not args: args = parser.parse_args()
args = ["-"] for arg in args.args:
for arg in args: if args.decompress:
if decompress:
if arg == "-": if arg == "-":
f = GzipFile(filename="", mode="rb", fileobj=sys.stdin.buffer) f = GzipFile(filename="", mode="rb", fileobj=sys.stdin.buffer)
g = sys.stdout.buffer g = sys.stdout.buffer
...@@ -571,4 +570,4 @@ def _test(): ...@@ -571,4 +570,4 @@ def _test():
f.close() f.close()
if __name__ == '__main__': if __name__ == '__main__':
_test() main()
Use argparse for the command line of the gzip module. Patch by Antony Lee
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment