Skip to content

Commit 68dd1dc

Browse files
matrixiseanntzer
andcommitted
bpo-23596: Use argparse for the command line of gzip
Co-authored-by: Antony Lee <anntzer.lee@gmail.com>
1 parent 84eec11 commit 68dd1dc

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

Lib/gzip.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -532,18 +532,17 @@ def decompress(data):
532532
return f.read()
533533

534534

535-
def _test():
536-
# Act like gzip; with -d, act like gunzip.
537-
# The input file is not deleted, however, nor are any other gzip
538-
# options or features supported.
539-
args = sys.argv[1:]
540-
decompress = args and args[0] == "-d"
541-
if decompress:
542-
args = args[1:]
543-
if not args:
544-
args = ["-"]
545-
for arg in args:
546-
if decompress:
535+
def main():
536+
from argparse import ArgumentParser
537+
parser = ArgumentParser(description=
538+
"A simple command line interface for the gzip module: act like gzip, "
539+
"but do not delete the input file.")
540+
parser.add_argument("-d", "--decompress", action="store_true",
541+
help="act like gunzip instead of gzip")
542+
parser.add_argument("args", nargs="*", default=["-"])
543+
args = parser.parse_args()
544+
for arg in args.args:
545+
if args.decompress:
547546
if arg == "-":
548547
f = GzipFile(filename="", mode="rb", fileobj=sys.stdin.buffer)
549548
g = sys.stdout.buffer
@@ -571,4 +570,4 @@ def _test():
571570
f.close()
572571

573572
if __name__ == '__main__':
574-
_test()
573+
main()

0 commit comments

Comments
 (0)