File tree Expand file tree Collapse file tree 1 file changed +12
-13
lines changed Expand file tree Collapse file tree 1 file changed +12
-13
lines changed Original file line number Diff line number Diff 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
573572if __name__ == '__main__' :
574- _test ()
573+ main ()
You can’t perform that action at this time.
0 commit comments