命令行TOML/JSON/INI/YAML/XML处理器,使用jqc绑定。

wildq的Python项目详细描述


wildq—使用jqc绑定的命令行TOML/JSON/INI/YAML/XML/HCL处理器

{1}$ imageBuild Status

这个包的目的是为不同格式的jq提供一个简单的包装器。 我已经厌倦了搜索一个包做yamljq,tomljq,ini jq等,主要用于脚本编写。在

此脚本使用:

安装

您可以通过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上是“可编译的”,所以我认为与该操作系统兼容的人可以做到这一点)

支持的文件类型

typecolororderingoutputsource
hcljsonnojsonpyhcl by @virtuald
iniyesnoyesConfigParser
jsonyesyesyesjson
tomlyesnoyestoml by @uiri
xmlyesnoyesxmldict by @martinblech
yamlyesyesyespyyaml

使用

$ 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 to jq -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

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java如何在数据库中存储工作日数据以及开始时间和结束时间?   mysql Java JPA内部联接查询不起作用   java MQ消息在不同的客户端应用程序中显示不同   javascript如何在xPage上提高typeAhead性能?   java在尝试保存EditText时无法暂停   mongodb“未能使用带参数的构造函数NO_构造函数实例化java.util.List”,   java如何修改使IllegalArgumentException:列“\u id”不存在的游标   转换Android。网Uri到Java。伊奥。输入流   java NetBeans RCP居中弹出窗口无法按预期工作   java将sql开发人员与netbeans连接起来   带有xmldsig签名的java JAXB编组   java ORACLE JDBC批处理执行不会返回受影响行的实际计数   java无法理解如何在由swagger自动生成的jaxrs服务器中访问请求头   java如何处理漏洞CVE20181258,同时将Spring安全版本5与外部客户端(最新版本)一起使用?   JavaSpring数据JPA存储库多租户单模式技术