1 个不稳定版本
0.1.0 | 2024 年 7 月 13 日 |
---|
#33 在 值格式化
94 每月下载次数
34KB
748 行
CTOML
一个用于读取、写入和从 TOML 文件中删除值的命令行界面工具。
目录
特性
- 读取:使用点符号和数组索引从 TOML 文件中检索值。
- 写入:修改或向 TOML 文件中添加新值,支持嵌套结构和数组。
- 删除:从 TOML 文件中删除键或数组元素。
- 支持复杂数据结构:处理嵌套表、数组和混合数据类型。
- 灵活的语法:使用点符号表示嵌套键和方括号表示数组索引。
安装
要安装 TOML CLI 编辑器,您需要在系统上安装 Rust 和 Cargo。如果您还没有安装它们,可以从 rustup.rs 安装。
安装 Rust 和 Cargo 后,您可以使用以下命令安装 TOML CLI 编辑器
cargo install ctoml
使用
使用 TOML CLI 编辑器的一般语法是
ctoml <file> <key> [value]
用于删除值
ctoml -r <file> <key>
其中
<file>
是您的 TOML 文件路径<key>
是您要操作的键(使用点符号表示嵌套键和方括号表示数组索引)[value]
是新值(仅适用于写入操作)
读取值
从 TOML 文件中读取值
ctoml <file> <key>
写入值
向 TOML 文件中写入值
ctoml <file> <key> <value>
删除值
从 TOML 文件中删除值
ctoml -r <file> <key>
示例
假设我们有一个包含以下内容的 sample.toml
文件
food.snickers.taste.sweet = true
[foo]
bar = "some string"
integers = [ 1, 2, 3 ]
colors = [ "red", "yellow", "green" ]
nested_arrays_of_ints = [ [ 1, 2 ], [3, 4, 5] ]
name = { first = "Tom", last = "Preston-Werner" }
[fruits]
apples = 3
bananas = 5
[[products]]
name = "Hammer"
sku = 738594937
[[products]]
name = "Nail"
sku = 284758393
读取示例
ctoml sample.toml foo.bar
# Output: some string
ctoml sample.toml foo.integers
# Output: [ 1, 2, 3 ]
ctoml sample.toml foo.integers[1]
# Output: 2
ctoml sample.toml foo.nested_arrays_of_ints[0][0]
# Output: 1
ctoml sample.toml foo.name.first
# Output: Tom
ctoml sample.toml products[1].sku
# Output: 284758393
写入示例
ctoml sample.toml foo.bar some_value
# Writes "some_value" string to foo.bar
ctoml sample.toml foo.integers [1, 2, 3]
# Writes [1, 2, 3] array to foo.integers
ctoml sample.toml foo.integers[1] 2
# Writes 2 to the second entry of foo.integers array
ctoml sample.toml foo.integers[] 5
# Adds 5 to the end of foo.integers array
ctoml sample.toml foo.integers[] [5, 6, 8]
# Adds three elements (5, 6, 8) to the end of foo.integers array
ctoml sample.toml products[1].name Nauk
# Sets value "Nauk" to the second element of products array table for key name
删除示例
ctoml -r sample.toml foo.integers
# Removes integers from foo
ctoml -r sample.toml foo.integers[:2]
# Removes the last 2 elements from foo.integers array
ctoml -r sample.toml foo.integers[2:]
# Removes the first 2 elements from foo.integers array
ctoml -r sample.toml foo.integers[1]
# Removes the second element from foo.integers array
ctoml -r sample.toml foo.integers[0,2,4]
# Removes elements at indices 0, 2, and 4 from foo.integers array
ctoml -r sample.toml foo.nested_arrays_of_ints[0][:1]
# Removes the last element from the first nested array in foo.nested_arrays_of_ints
贡献
欢迎贡献!请随时提交拉取请求。
许可证
本项目采用MIT许可协议 - 请参阅LICENSE文件以获取详细信息。
依赖项
~0.6–1.2MB
~24K SLoC