shell 讀取yaml 之 shyaml


 

安裝shyaml
pip3.7 install shyaml


file.yaml文件內容
---
idc_group:
name: bx
bx:
news_bx: news_bx
web3_bx: web3_php-fpm_bx
task: [1,2,3,4,5,6]






(testenv3.7) localhost:testenv3.7 macname$ cat file.yaml | shyaml get-value idc_group.name
bx
(testenv3.7) localhost:testenv3.7 macname$ 
(testenv3.7) localhost:testenv3.7 macname$ cat file.yaml | shyaml key-values idc_group.bx
news_bx
news_bx
web3_bx
web3_php-fpm_bx
(testenv3.7) localhost:testenv3.7 macname$ 

 

例子

get-value:獲取值
(testenv3.7) localhost:testenv3.7 macname$ cat file.yaml | shyaml get-value idc_group.bx.news_bx
news_bx
(testenv3.7) localhost:testenv3.7 macname$ 



get-type:獲取相應的類型
(testenv3.7) localhost:testenv3.7 macname$ cat file.yaml | shyaml get-type idc_group.bx.news_bx
str
(testenv3.7) localhost:testenv3.7 macname$ 



get-values{,-0}:對序列類型來說,獲取值列表
(testenv3.7) localhost:testenv3.7 macname$ cat file.yaml | shyaml get-values idc_group.bx.task
1
2
3
4
5
6
(testenv3.7) localhost:testenv3.7 macname$ 



keys{,-0}:返回鍵列表
(testenv3.7) localhost:testenv3.7 macname$ cat file.yaml | shyaml keys idc_group
name
bx
(testenv3.7) localhost:testenv3.7 macname$ cat file.yaml | shyaml keys idc_group.bx
news_bx
web3_bx
task
(testenv3.7) localhost:testenv3.7 macname$ 




values{,-0}:返回值列表
(testenv3.7) localhost:testenv3.7 macname$ cat file.yaml | shyaml values idc_group.bx
news_bx
web3_php-fpm_bx
- 1
- 2
- 3
- 4
- 5
- 6
(testenv3.7) localhost:testenv3.7 macname$ cat file.yaml | shyaml values idc_group
bx
news_bx: news_bx
web3_bx: web3_php-fpm_bx
task:
- 1
- 2
- 3
- 4
- 5
- 6
(testenv3.7) localhost:testenv3.7 macname$ 





key-values,{,-0}:返回鍵值對
(testenv3.7) localhost:testenv3.7 macname$ cat file.yaml | shyaml key-values idc_group.bx
news_bx
news_bx
web3_bx
web3_php-fpm_bx
task
- 1
- 2
- 3
- 4
- 5
- 6
(testenv3.7) localhost:testenv3.7 macname$ cat file.yaml | shyaml key-values idc_group
name
bx
bx
news_bx: news_bx
web3_bx: web3_php-fpm_bx
task:
- 1
- 2
- 3
- 4
- 5
- 6
(testenv3.7) localhost:testenv3.7 macname$ 

 

 

 

參考:

https://www.linuxidc.com/Linux/2016-04/130403.htm


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM