如何从命令行验证我的 YAML 文件? [英] How do I validate my YAML file from command line?

查看:33
本文介绍了如何从命令行验证我的 YAML 文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在从 YAML 配置文件中提取时遇到问题:

I am having issues pulling from a YAML config file:

致命错误:解析块映射时;预期<块结束>,但找到块入口

Fatal error: while parsing a block mapping; expected <block end>, but found block entry

虽然有很多在线 YAML 验证器,我尝试过并提供了帮助,但我想从命令行验证我的 YAML 文件并将其集成到我的持续集成管道中.

While there are plenty of online YAML validators, which I have tried and have helped, I'd like to validate my YAML files from the command line and integrate this into my continuous integration pipeline.

如何在命令行上验证 YAML 文件的语法?

推荐答案

使用基本的 Ruby 安装,这应该可以工作:

With basic Ruby installation this should work:

ruby -ryaml -e "p YAML.load(STDIN.read)" < data.yaml

Python 版本(感谢 @Murphy):

Python version (thx @Murphy):

pip install pyyaml
python -c 'import yaml, sys; print(yaml.safe_load(sys.stdin))' < data.yaml

这篇关于如何从命令行验证我的 YAML 文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆