| Crates.io | i_edit_yaml |
| lib.rs | i_edit_yaml |
| version | 0.1.0 |
| created_at | 2025-12-08 03:54:30.562397+00 |
| updated_at | 2025-12-08 03:54:30.562397+00 |
| description | A lightweight, high-performance tool for editing YAML based on field paths |
| homepage | |
| repository | https://github.com/ymc-github/i_edit_yaml |
| max_upload_size | |
| id | 1972702 |
| size | 331,919 |
一个轻量级、高性能的、基于字段路径的 YAML 编辑工具。
cargo install i_edit_yaml
git clone https://github.com/ymc-github/i_edit_yaml
cd i_edit_yaml
cargo install --path .
# 从 GitHub 安装
cargo install --git https://github.com/ymc-github/i_edit_yaml
# 指定分支
cargo install --git https://github.com/ymc-github/i_edit_yaml --branch main
# 指定标签
cargo install --git https://github.com/ymc-github/i_edit_yaml --tag v0.1.0
# 基本使用
i_edit_yaml get -f config.yaml -k package.name
# 提取数组
i_edit_yaml get --array package.authors
# 提取数组元素
i_edit_yaml get --array-element package.authors --array-index 0
# 提取数组长度
i_edit_yaml get --array-length package.keywords
# 提取映射的所有键
i_edit_yaml get --mapping-keys dependencies
# 提取多个字段
i_edit_yaml get -m package.name -m package.version -m package.authors
# 输出为 JSON 格式
i_edit_yaml get -k dependencies --output json-pretty
# 输出为 YAML 格式
i_edit_yaml get -k package --output yaml-pretty
# 基本使用
i_edit_yaml set -f config.yaml -k package.version -v "1.0.0" --in-place
# 设置数组元素
i_edit_yaml set -k package.authors[0] -v "New Author <author@example.com>" --in-place
# 创建不存在的字段
i_edit_yaml set -k package.description -v "A new description" --create-missing --in-place
# 指定值类型
i_edit_yaml set -k package.enabled -v "true" -t boolean --in-place
# 设置 null 值
i_edit_yaml set -k package.optional -v "null" -t null --in-place
添加依赖到 Cargo.toml:
[dependencies]
i_edit_yaml = "0.1"
在代码中使用:
use i_edit_yaml::{get, set, ExtractConfig, SetConfig};
fn main() -> Result<(), Box<dyn std::error::Error>> {
// 提取字段
let get_config = ExtractConfig {
file_path: "config.yaml".to_string(),
field_path: "database.host".to_string(),
output_format: None,
strip_quotes: true,
};
let host = get::extract_field(&get_config)?;
println!("Database host: {}", host);
// 设置字段
let set_config = SetConfig {
file_path: "config.yaml".to_string(),
field_path: "database.port".to_string(),
value: "5432".to_string(),
value_type: Some("integer".to_string()),
create_missing: false,
};
set::set_field_and_save(&set_config)?;
println!("Database port updated successfully");
Ok(())
}
MIT OR Apache-2.0