diff options
author | Semyon Moroz <donbarbos@proton.me> | 2025-03-17 13:36:30 +0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-03-17 09:36:30 +0000 |
commit | 85c04f80fd3a3098674f60038f248c076a476acf (patch) | |
tree | cfe41a4c636bdf90c75f831198262f91e7c0fcb0 /Lib | |
parent | a1aeec61c4321ba9a6966109343bd88dcf9cb26a (diff) | |
download | cpython-85c04f80fd3a3098674f60038f248c076a476acf.tar.gz cpython-85c04f80fd3a3098674f60038f248c076a476acf.zip |
gh-93096: Update and document `pickletools` CLI (#131273)
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/pickletools.py | 43 |
1 files changed, 20 insertions, 23 deletions
diff --git a/Lib/pickletools.py b/Lib/pickletools.py index 02aad12985d..53f25ea4e46 100644 --- a/Lib/pickletools.py +++ b/Lib/pickletools.py @@ -2845,7 +2845,7 @@ if __name__ == "__main__": description='disassemble one or more pickle files') parser.add_argument( 'pickle_file', - nargs='*', help='the pickle file') + nargs='+', help='the pickle file') parser.add_argument( '-o', '--output', help='the file where the output should be written') @@ -2863,26 +2863,23 @@ if __name__ == "__main__": help='if more than one pickle file is specified, print this before' ' each disassembly') args = parser.parse_args() - if not args.pickle_file: - parser.print_help() + annotate = 30 if args.annotate else 0 + memo = {} if args.memo else None + if args.output is None: + output = sys.stdout else: - annotate = 30 if args.annotate else 0 - memo = {} if args.memo else None - if args.output is None: - output = sys.stdout - else: - output = open(args.output, 'w') - try: - for arg in args.pickle_file: - if len(args.pickle_file) > 1: - name = '<stdin>' if arg == '-' else arg - preamble = args.preamble.format(name=name) - output.write(preamble + '\n') - if arg == '-': - dis(sys.stdin.buffer, output, memo, args.indentlevel, annotate) - else: - with open(arg, 'rb') as f: - dis(f, output, memo, args.indentlevel, annotate) - finally: - if output is not sys.stdout: - output.close() + output = open(args.output, 'w') + try: + for arg in args.pickle_file: + if len(args.pickle_file) > 1: + name = '<stdin>' if arg == '-' else arg + preamble = args.preamble.format(name=name) + output.write(preamble + '\n') + if arg == '-': + dis(sys.stdin.buffer, output, memo, args.indentlevel, annotate) + else: + with open(arg, 'rb') as f: + dis(f, output, memo, args.indentlevel, annotate) + finally: + if output is not sys.stdout: + output.close() |