命令行TOML/JSON/INI/YAML/XML处理器,使用jqc绑定。
wildq的Python项目详细描述
wildq—使用jqc绑定的命令行TOML/JSON/INI/YAML/XML/HCL处理器
这个包的目的是为不同格式的jq提供一个简单的包装器。 我已经厌倦了搜索一个包做yamljq,tomljq,ini jq等,主要用于脚本编写。在
此脚本使用:
- @mwilliamson Python bindings在@stedolan-familyjqlib之上
- 瑞士染色刀pygments
- 用pyinstaller生成的二进制文件
- 使用click的简单CLI
- 对于支持的类型源,请检查表
Supported file types
安装
您可以通过pipx、pip、brew、deb、rpm或回退到二进制版本进行安装。在
皮克斯
pipx
在隔离环境中安装并运行python应用程序
pipx install wildq
皮普
^{pr2}$马科斯
brew install ahmet2mir/tap/wildq
brew install ahmet2mir/tap/wq
Debian(无gpg签名)>;=10
VERSION=$(curl -s "https://api.github.com/repos/ahmet2mir/wildq/releases/latest" | grep '"tag_name":' | sed -E 's/.*"v([^"]+)".*/\1/')
curl -sL https://github.com/ahmet2mir/wildq/releases/download/v${VERSION}/wildq_${VERSION}-1_amd64.deb -o wildq_${VERSION}-1_amd64.deb
sudo dpkg -i wildq_${VERSION}-1_amd64.deb
wq --help
wildq --help
Centos(无gpg信号)>;=7
VERSION=$(curl -s "https://api.github.com/repos/ahmet2mir/wildq/releases/latest" | grep '"tag_name":' | sed -E 's/.*"v([^"]+)".*/\1/')
curl -sL https://github.com/ahmet2mir/wildq/releases/download/v${VERSION}/wildq-${VERSION}-1.x86_64.rpm -o wildq-${VERSION}-1.x86_64.rpm
sudo yum install -y ./wildq-${VERSION}-1.x86_64.rpm
wq --help
wildq --help
GNU/Linux二进制文件
它是用glibc2.17编译的,应该可以在很多稳定的/LTS发行版上运行。在
mkdir -p ~/bin/
VERSION=$(curl -s "https://api.github.com/repos/ahmet2mir/wildq/releases/latest" | grep '"tag_name":' | sed -E 's/.*"v([^"]+)".*/\1/')
curl -sL https://github.com/ahmet2mir/wildq/releases/download/v${VERSION}/wildq-${VERSION}-linux-x86_64.tar.gz -o wildq-${VERSION}-linux-x86_64.tar.gz
tar xvfz wildq-${VERSION}-linux-x86_64.tar.gz -C ~/bin
export PATH="~/bin:$PATH"
wq --help
wildq --help
窗口
Wildq使用jq.py,但它在windows平台上还不可用。 我试图在没有windows machine的情况下编译它,但是失败了,我没有时间去理解windows/C绑定/Python是如何工作的。 如果有人愿意贡献的话,有一个open issue(jq和onigurama在Windows上是“可编译的”,所以我认为与该操作系统兼容的人可以做到这一点)
支持的文件类型
type | color | ordering | output | source |
---|---|---|---|---|
hcl | json | no | json | pyhcl by @virtuald |
ini | yes | no | yes | ConfigParser |
json | yes | yes | yes | json |
toml | yes | no | yes | toml by @uiri |
xml | yes | no | yes | xmldict by @martinblech |
yaml | yes | yes | yes | pyyaml |
使用
$ wildq --help
Usage: wildq [OPTIONS] JQ_FILTER [FILE]
Options:
-c, --compact-output compact instead of pretty-printed output
-r, --raw output raw strings, not content texts
-C, --color-output colorize content (default), mutally
exclusive with --monochrome-output
-M, --monochrome-output monochrome (don't colorize content), mutally
exclusive with --color-output
--hcl Combine --input hcl --output json, mutally
exclusive with other Combined options
--ini Combine --input ini --output json, mutally
exclusive with other Combined options
--json Combine --input json --output json, mutally
exclusive with other Combined options
--toml Combine --input toml --output json, mutally
exclusive with other Combined options
--xml Combine --input xml --output json, mutally
exclusive with other Combined options
--yaml Combine --input yaml --output json, mutally
exclusive with other Combined options
-i, --input [hcl|ini|json|toml|xml|yaml]
Define the content type of file, mutally
exclusive with Combined option
-o, --output [hcl|ini|json|toml|xml|yaml]
Define the content type of printed output,
mutally exclusive with Combined option
(default input format)
--version Show the version and exit.
--help Show this message and exit.
For backward compatibility in previous version only
--[yaml|json|toml|ini|xml|hcl]
was possible with default to json output. We still keep Monochrome, raw and json output with thoses options. Output was similar tojq -MCr
(no color, no compact and no quote on single value)
但现在,默认情况下,它是彩色的,而不是原始的,如果使用-i
或--input
指定输入,则输出将是相同的格式。在
包中还有一个更短的命令wq
。在
像jq cli
,wildq同时支持stdin和file到函数
请参阅示例以获取一些示例。在
examples/json.json
的内容
{
"general": {
"user": "admin"
},
"keys": [
{"key": "value1"},
{"key": "value2"},
"alone"
]
}
cat examples/json.json | wildq -i json ".keys[]"{"key": "value1"}{"key": "value2"} alone
或者
wildq -i json ".keys[]" examples/json.json {"key": "value1"}{"key": "value2"} alone
或者
wq -i json ".keys[]" examples/json.json {"key": "value1"}{"key": "value2"} alone
对于TOML
cat examples/toml.toml | wildq -i toml ".keys[]"{"key": "value1"}{"key": "value2"} alone
对于INI(无数组)
cat examples/ini.ini | wildq -i ini ".keys"{"key1": "value1", "key2": "value2"}
对于XML
cat examples/xml.xml | wildq -i xml "."{"root": {"general": {"user": "admin"}, "keys": {"element": [{"key": "value1"}, {"key": "value2"}, "alone"]}}}
对于山药
cat examples/yaml.yaml | wildq -i yaml ".keys[]"{"key1": "value1"}{"key2": "value2"} alone
对于HCL
cat examples/hcl.hcl | wildq -i hcl ".keys[]"{"key": "value1"}{"key": "value2"}
提示和技巧
在bash中循环键而不创建子shell
wildq -i toml "keys[]" examples/toml.toml |whileread -r key doecho"Getting key ${key}"done
托多
- [x] 添加测试。。。在
- [x] 添加对过滤器和文件的更多控制
- [x] 对CLI使用click
- [x] 支持不同的输出
- []自动检测文件类型
- []支持所有jq类型
- []订购
贡献
欢迎合并请求:)
许可证
根据Apache License, Version 2.0条款授权。在
存储库URL
https://github.com/ahmet2mir/wildq
- 项目
标签: