Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e8bbc52

Browse files
matrixiseanntzer
authored andcommitted
bpo-23596: Use argparse for the command line of gzip (GH-9781)
Co-authored-by: Antony Lee <[email protected]>
1 parent 84eec11 commit e8bbc52

2 files changed

Lines changed: 13 additions & 13 deletions

File tree

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=["-"], metavar='file')
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()
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Use argparse for the command line of the gzip module. Patch by Antony Lee

0 commit comments

Comments
 (0)