基于ruamel.yaml的固执己见的yaml形成剂
yamlfmt的Python项目详细描述
yamlfmt
一个简单的自定义yaml格式化程序,可以保存您的评论!
yamlfmt
只是ruamel.yamlpython库周围的一个cli包装器,它碰巧具有保存注释的独特质量。
使用量
注释: 所用格式如有更改,恕不另行通知。 一旦一个格式似乎坚持v1.0将被标记,格式将不会改变。
❯ yamlfmt -h usage: yamlfmt [-h][-w][file [file ...]] positional arguments: file file to parse optional arguments: -h, --help show this help message and exit -w, --write write formatted outpout to (source) file instead of stdout
示例
让我们看看yamlfmt
的实际效果:
ruamel.yaml文档中的简单示例
❯ yamlfmt <<EOF# examplename: # details family: Smith # very common given: Alice # one of the siblingsEOF# example
name:
# details
family: Smith # very common
given: Alice # one of the siblings
travis ci nodejs示例
❯ yamlfmt <<EOFlanguage: node_js# test on two node.js versions: 0.6 and 0.8node_js: - 0.6 - 0.8# configure notifications (email, IRC, campfire etc)# please update this section to your needs!notifications: irc: "irc.freenode.org#travis"EOF
language: node_js
# test on two node.js versions: 0.6 and 0.8
node_js:
- 0.6
- 0.8
# configure notifications (email, IRC, campfire etc)# please update this section to your needs!
notifications:
irc: irc.freenode.org#travis
ruamel.yaml文档中的复杂示例
❯ yamlfmt <<EOF- &CENTER {x: 1, y: 2}- &LEFT {x: 0, y: 2}- &BIG {r: 10}- &SMALL {r: 1}# All the following maps are equal:# Explicit keys- x: 1 y: 2 r: 10 label: center/big# Merge one map- <<: *CENTER r: 10 label: center/big# Merge multiple maps- <<: [*CENTER, *BIG] label: center/big# Override- <<: [*BIG, *LEFT, *SMALL] x: 1 label: center/bigEOF
- &CENTER {x: 1, y: 2}
- &LEFT {x: 0, y: 2}
- &BIG {r: 10}
- &SMALL {r: 1}# All the following maps are equal:# Explicit keys
- x: 1
y: 2
r: 10
label: center/big
# Merge one map
- <<: *CENTER
r: 10
label: center/big
# Merge multiple maps
- <<: [*CENTER, *BIG]
label: center/big
# Override
- <<: [*BIG, *LEFT, *SMALL]
x: 1
label: center/big
❯ yamlfmt <<EOFlanguage: node_js# test on two node.js versions: 0.6 and 0.8node_js: - 0.6 - 0.8# configure notifications (email, IRC, campfire etc)# please update this section to your needs!notifications: irc: "irc.freenode.org#travis"EOF language: node_js # test on two node.js versions: 0.6 and 0.8 node_js: - 0.6 - 0.8 # configure notifications (email, IRC, campfire etc)# please update this section to your needs! notifications: irc: irc.freenode.org#travis
ruamel.yaml文档中的复杂示例
❯ yamlfmt <<EOF- &CENTER {x: 1, y: 2}- &LEFT {x: 0, y: 2}- &BIG {r: 10}- &SMALL {r: 1}# All the following maps are equal:# Explicit keys- x: 1 y: 2 r: 10 label: center/big# Merge one map- <<: *CENTER r: 10 label: center/big# Merge multiple maps- <<: [*CENTER, *BIG] label: center/big# Override- <<: [*BIG, *LEFT, *SMALL] x: 1 label: center/bigEOF - &CENTER {x: 1, y: 2} - &LEFT {x: 0, y: 2} - &BIG {r: 10} - &SMALL {r: 1}# All the following maps are equal:# Explicit keys - x: 1 y: 2 r: 10 label: center/big # Merge one map - <<: *CENTER r: 10 label: center/big # Merge multiple maps - <<: [*CENTER, *BIG] label: center/big # Override - <<: [*BIG, *LEFT, *SMALL] x: 1 label: center/big