geeks4change/treetool
Composer 安装命令:
composer create-project geeks4change/treetool
包简介
Makes changes on .json and .yml files.
README 文档
README
The swiss army bread and butter knife for .json and .yml files.
Install
composer require geeks4change/treetool
Examples
$ # Add a patch entry to composer.json.
$ # --file/-f does in-place editing and is shorthand for --in/-i & --out/-o.
$ bin/tt set -f composer.json extra patches drupal/core "My cool patch" https://drupal.org/files/my-cool.patch
$ # Let's see what this did. Use --in/-i instead of -f to read from file and write to stdout.
$ bin/tt get -i composer.json extra
{
"patches": {
"drupal/core": {
"My cool patch": "https://drupal.org/files/my-cool.patch"
}
}
}
$ # Note that 'get' does not have -f/--file in-place edit option to protect you.
$ bin/tt get -f composer.json extra patches drupal/core
The "-f" option does not exist.
$ # Of course with a mighty tool you can make mighty mistakes. But you use VCS, don't you?
$ # Or you can preview a change with -i, and only then apply it with -f.
$ # Without the --replace option, 'set' refuses to overwrite arrays with values and values with arrays..
$ bin/tt set -f composer.json extra "This text replaces the complete extra subtree."
[ERROR] Can not replace array at key extra with value without --replace/-r.
$ # We can later remove the patch.
$ bin/tt del -f composer.json extra patches drupal/core "My coool patch"
$ # When we look what we've got, we see some leftover empty arrays.
$ bin/tt get -i composer.json extra
{
"patches": {
"drupal/core": []
}
}
$ # This need not be. Del command can clean up empty arrays.
$ bin/tt del -f composer.json extra patches drupal/core "My coool patch" --clean
$ bin/tt get -i composer.json extra
null
Edit Json as Yaml
$ # Yaml is a lot easier to edit:
$ bin/tt edit composer.json
Advanced examples
$ # Let's see our patch as --out-type=yml
$ bin/tt get -i composer.json extra -u yml
patches:
drupal/core:
'My coool patch': 'https://drupal.org/files/my-cool.patch'
$ # I want to extract that patch for my script.
$ bin/tt get -i composer.json extra patches drupal/core "My coool patch"
"https://drupal.org/files/my-cool.patch"
$ # But i want that value without the quotes. And error code 0 for success.
$ bin/tt get -i composer.json extra patches drupal/core "My coool patch" -u plain
https://drupal.org/files/my-cool.patch
$ echo $?
0
$ bin/tt get -i composer.json extra patches drupal/core "No patch here" -u plain
[ERROR] Result is not a string or number.
$ echo $?
5
$ # For an empty set of keys, the provided value will replace the root element.
$ bin/tt set -i composer.json "This string replaces everything" --replace
"This string replaces everything"
$ # You can do pipes. Excessive pipes.
$ echo '' | bin/tt set foo bar baz value | bin/tt set foo bong boom whatnot | bin/tt del foo bar baz
foo:
bar: { }
bong:
boom: whatnot
$ # You can leverage the 'type' command to get the type of any data.
$ export data='{"foo": 17, "bar": 42}'; echo $data|bin/tt type
object
$ export data='{"foo": 17, "bar": 42}'; echo $data|bin/tt get foo|bin/tt type
number
$ If you are nerdy enough, you can leverage the 'keys' command to write an XSLT processor in bash.
$ export data='{"foo": 17, "bar": 42}'; echo $data|bin/tt keys|while IFS="\n" read -r k; do export k; v=$(echo "$data" |bin/tt get "$k"); echo "Key $k has value $v"; done
Key foo has value 17
Key bar has value 42
Help
bin/tt help get
bin/tt help set
bin/tt help del
bin/tt help type
bin/tt help keys
Contributing
If you want to contribute PHPUnit tests, Gitlab CI testing, Phar creation, or a Rust implementation, go ahead and submit a PR, it will be appreciated.
For everything else, submit an issue so we can see how it fits the bread-and-butter nature of this project.
geeks4change/treetool 适用场景与选型建议
geeks4change/treetool 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 65 次下载、GitHub Stars 达 0, 最近一次更新时间为 2020 年 12 月 11 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 geeks4change/treetool 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 geeks4change/treetool 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 65
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: gpl-2.0-or-later
- 更新时间: 2020-12-11