style: 格式化代码并优化导入顺序
This commit is contained in:
@@ -9,15 +9,12 @@ pub fn edit_content(initial_content: &str) -> Result<String> {
|
||||
|
||||
/// Edit file in user's default editor
|
||||
pub fn edit_file(path: &Path) -> Result<String> {
|
||||
let content = fs::read_to_string(path)
|
||||
.unwrap_or_default();
|
||||
|
||||
let edited = edit::edit(&content)
|
||||
.context("Failed to open editor")?;
|
||||
|
||||
fs::write(path, &edited)
|
||||
.with_context(|| format!("Failed to write file: {:?}", path))?;
|
||||
|
||||
let content = fs::read_to_string(path).unwrap_or_default();
|
||||
|
||||
let edited = edit::edit(&content).context("Failed to open editor")?;
|
||||
|
||||
fs::write(path, &edited).with_context(|| format!("Failed to write file: {:?}", path))?;
|
||||
|
||||
Ok(edited)
|
||||
}
|
||||
|
||||
@@ -27,11 +24,10 @@ pub fn edit_temp(initial_content: &str, extension: &str) -> Result<String> {
|
||||
.suffix(&format!(".{}", extension))
|
||||
.tempfile()
|
||||
.context("Failed to create temp file")?;
|
||||
|
||||
|
||||
let path = temp_file.path();
|
||||
fs::write(path, initial_content)
|
||||
.context("Failed to write temp file")?;
|
||||
|
||||
fs::write(path, initial_content).context("Failed to write temp file")?;
|
||||
|
||||
edit_file(path)
|
||||
}
|
||||
|
||||
@@ -65,7 +61,6 @@ pub fn get_editor() -> String {
|
||||
/// Check if editor is available
|
||||
pub fn check_editor() -> Result<()> {
|
||||
let editor = get_editor();
|
||||
which::which(&editor)
|
||||
.with_context(|| format!("Editor '{}' not found in PATH", editor))?;
|
||||
which::which(&editor).with_context(|| format!("Editor '{}' not found in PATH", editor))?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user