mirror of
https://github.com/python/cpython.git
synced 2025-10-07 07:31:46 +00:00
bpo-23596: Use argparse for the command line of gzip (GH-9781)
Co-authored-by: Antony Lee <anntzer.lee@gmail.com>
This commit is contained in:
parent
84eec11995
commit
e8bbc52deb
2 changed files with 13 additions and 13 deletions
25
Lib/gzip.py
25
Lib/gzip.py
|
@ -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():
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
_test()
|
main()
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Use argparse for the command line of the gzip module. Patch by Antony Lee
|
Loading…
Add table
Add a link
Reference in a new issue