diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2017-04-07 15:56:12 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-04-07 15:56:12 (GMT) |
commit | 150cd1916a59e750ce88c65325de9ef0c42c6cb5 (patch) | |
tree | 546e715a7883526a32430d58791636768724d755 /Lib/tarfile.py | |
parent | fd0cd07a5a3c964c084f4efc5bbcb89dd2193ee6 (diff) | |
download | cpython-150cd1916a59e750ce88c65325de9ef0c42c6cb5.zip cpython-150cd1916a59e750ce88c65325de9ef0c42c6cb5.tar.gz cpython-150cd1916a59e750ce88c65325de9ef0c42c6cb5.tar.bz2 |
bpo-29958: Minor improvements to zipfile and tarfile CLI. (#944)
Diffstat (limited to 'Lib/tarfile.py')
-rwxr-xr-x | Lib/tarfile.py | 15 |
1 files changed, 6 insertions, 9 deletions
diff --git a/Lib/tarfile.py b/Lib/tarfile.py index 2d702dd..9d46e5f 100755 --- a/Lib/tarfile.py +++ b/Lib/tarfile.py @@ -2450,11 +2450,11 @@ open = TarFile.open def main(): import argparse - description = 'A simple command line interface for tarfile module.' + description = 'A simple command-line interface for tarfile module.' parser = argparse.ArgumentParser(description=description) parser.add_argument('-v', '--verbose', action='store_true', default=False, help='Verbose output') - group = parser.add_mutually_exclusive_group() + group = parser.add_mutually_exclusive_group(required=True) group.add_argument('-l', '--list', metavar='<tarfile>', help='Show listing of a tarfile') group.add_argument('-e', '--extract', nargs='+', @@ -2467,7 +2467,7 @@ def main(): help='Test if a tarfile is valid') args = parser.parse_args() - if args.test: + if args.test is not None: src = args.test if is_tarfile(src): with open(src, 'r') as tar: @@ -2478,7 +2478,7 @@ def main(): else: parser.exit(1, '{!r} is not a tar archive.\n'.format(src)) - elif args.list: + elif args.list is not None: src = args.list if is_tarfile(src): with TarFile.open(src, 'r:*') as tf: @@ -2486,7 +2486,7 @@ def main(): else: parser.exit(1, '{!r} is not a tar archive.\n'.format(src)) - elif args.extract: + elif args.extract is not None: if len(args.extract) == 1: src = args.extract[0] curdir = os.curdir @@ -2508,7 +2508,7 @@ def main(): else: parser.exit(1, '{!r} is not a tar archive.\n'.format(src)) - elif args.create: + elif args.create is not None: tar_name = args.create.pop(0) _, ext = os.path.splitext(tar_name) compressions = { @@ -2534,8 +2534,5 @@ def main(): if args.verbose: print('{!r} file created.'.format(tar_name)) - else: - parser.exit(1, parser.format_help()) - if __name__ == '__main__': main() |