style: 应用 rustfmt 格式化
整理 components、commands、entity 和 utils 中的 import 顺序、尾逗号、换行与文件末尾换行。 这保持代码风格与 rustfmt 输出一致,减少后续功能提交里的格式噪音。
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
use crate::commands::ComponentsArgs;
|
use crate::commands::ComponentsArgs;
|
||||||
use crate::entity;
|
use crate::entity;
|
||||||
use crate::utils::file;
|
|
||||||
use crate::error::Result;
|
use crate::error::Result;
|
||||||
|
use crate::utils::file;
|
||||||
use serde_json::{json, to_string_pretty};
|
use serde_json::{json, to_string_pretty};
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
@@ -28,11 +28,12 @@ fn run_components(args: &ComponentsArgs) -> Result<()> {
|
|||||||
args.geo.as_deref().unwrap_or("./model.geo.json"),
|
args.geo.as_deref().unwrap_or("./model.geo.json"),
|
||||||
args.texture.as_deref().unwrap_or("./texture.png"),
|
args.texture.as_deref().unwrap_or("./texture.png"),
|
||||||
identifier,
|
identifier,
|
||||||
&project_path
|
&project_path,
|
||||||
),
|
),
|
||||||
_ => Err(crate::error::CliError::NotFound(
|
_ => Err(crate::error::CliError::NotFound(format!(
|
||||||
format!("组件 '{}' 不存在", args.component)
|
"组件 '{}' 不存在",
|
||||||
)),
|
args.component
|
||||||
|
))),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -41,15 +42,17 @@ fn validate_input_files(geo: &Option<String>, texture: &Option<String>) -> Resul
|
|||||||
let texture_path = texture.as_deref().unwrap_or("./texture.png");
|
let texture_path = texture.as_deref().unwrap_or("./texture.png");
|
||||||
|
|
||||||
if !PathBuf::from(geo_path).exists() {
|
if !PathBuf::from(geo_path).exists() {
|
||||||
return Err(crate::error::CliError::NotFound(
|
return Err(crate::error::CliError::NotFound(format!(
|
||||||
format!("几何文件 {} 不存在", geo_path)
|
"几何文件 {} 不存在",
|
||||||
));
|
geo_path
|
||||||
|
)));
|
||||||
}
|
}
|
||||||
|
|
||||||
if !PathBuf::from(texture_path).exists() {
|
if !PathBuf::from(texture_path).exists() {
|
||||||
return Err(crate::error::CliError::NotFound(
|
return Err(crate::error::CliError::NotFound(format!(
|
||||||
format!("材质文件 {} 不存在", texture_path)
|
"材质文件 {} 不存在",
|
||||||
));
|
texture_path
|
||||||
|
)));
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -137,12 +140,7 @@ fn create_resource_item_json(identifier: &str) -> serde_json::Value {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn copy_assets(
|
fn copy_assets(res_path: &PathBuf, geo: &str, texture: &str, identifier: &str) -> Result<()> {
|
||||||
res_path: &PathBuf,
|
|
||||||
geo: &str,
|
|
||||||
texture: &str,
|
|
||||||
identifier: &str,
|
|
||||||
) -> Result<()> {
|
|
||||||
let f_identifier = identifier.replace(":", "_");
|
let f_identifier = identifier.replace(":", "_");
|
||||||
|
|
||||||
copy_texture(res_path, texture, &f_identifier)?;
|
copy_texture(res_path, texture, &f_identifier)?;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
use clap::{arg, Args, Parser, Subcommand};
|
use clap::{Args, Parser, Subcommand, arg};
|
||||||
|
|
||||||
pub mod components;
|
pub mod components;
|
||||||
pub mod create;
|
pub mod create;
|
||||||
@@ -68,5 +68,5 @@ pub struct ComponentsArgs {
|
|||||||
pub texture: Option<String>,
|
pub texture: Option<String>,
|
||||||
/// The item's identifier
|
/// The item's identifier
|
||||||
#[arg(short, long)]
|
#[arg(short, long)]
|
||||||
pub identifier: Option<String>
|
pub identifier: Option<String>,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,9 +7,8 @@ use std::{
|
|||||||
|
|
||||||
pub fn read_file_to_json(path: &PathBuf) -> Result<Value> {
|
pub fn read_file_to_json(path: &PathBuf) -> Result<Value> {
|
||||||
let content = fs::read_to_string(path).map_err(|e| io_error("读取文件", path, e))?;
|
let content = fs::read_to_string(path).map_err(|e| io_error("读取文件", path, e))?;
|
||||||
serde_json::from_str(&content).map_err(|e| {
|
serde_json::from_str(&content)
|
||||||
CliError::InvalidData(format!("解析 JSON '{}' 失败: {}", path.display(), e))
|
.map_err(|e| CliError::InvalidData(format!("解析 JSON '{}' 失败: {}", path.display(), e)))
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn write_json_to_file(path: &PathBuf, value: &Value) -> Result<()> {
|
pub fn write_json_to_file(path: &PathBuf, value: &Value) -> Result<()> {
|
||||||
|
|||||||
Reference in New Issue
Block a user