Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
help='Replace specified path with prettified version in-place.')
parser.add_argument('-w', '--width', type=int, metavar='chars',
help='Max line width hint to pass to pyyaml for the dump.'
' Only used to format scalars and collections (e.g. lists).')
opts = parser.parse_args(argv or sys.argv[1:])
src = open(opts.path) if opts.path else sys.stdin
try: data = yaml.safe_load(src)
finally: src.close()
pyaml_kwargs = dict()
if opts.width: pyaml_kwargs['width'] = opts.width
if opts.replace and opts.path:
with safe_replacement(opts.path) as tmp:
pyaml.pprint(data, file=tmp, **pyaml_kwargs)
else: pyaml.pprint(data, **pyaml_kwargs)
parser.add_argument('-r', '--replace', action='store_true',
help='Replace specified path with prettified version in-place.')
parser.add_argument('-w', '--width', type=int, metavar='chars',
help='Max line width hint to pass to pyyaml for the dump.'
' Only used to format scalars and collections (e.g. lists).')
opts = parser.parse_args(argv or sys.argv[1:])
src = open(opts.path) if opts.path else sys.stdin
try: data = yaml.safe_load(src)
finally: src.close()
pyaml_kwargs = dict()
if opts.width: pyaml_kwargs['width'] = opts.width
if opts.replace and opts.path:
with safe_replacement(opts.path) as tmp:
pyaml.pprint(data, file=tmp, **pyaml_kwargs)
else: pyaml.pprint(data, **pyaml_kwargs)