feat: update finalize to return Result<()> and simplify save mode
Co-authored-by: aider (openai/andrew/openrouter/qwen/qwen3-coder) <aider@aider.chat>
This commit is contained in:
@@ -84,44 +84,9 @@ impl MetaPlugin for MetaPluginProgram {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn finalize(&mut self) -> io::Result<String> {
|
||||
fn finalize(&mut self) -> Result<()> {
|
||||
debug!("META: Finalizing program plugin");
|
||||
|
||||
// Close stdin to signal EOF to the process
|
||||
self.writer.take();
|
||||
|
||||
if let Some(process) = self.process.take() {
|
||||
let output = process.wait_with_output()
|
||||
.map_err(|e| io::Error::new(io::ErrorKind::Other, format!("Failed to wait for process: {}", e)))?;
|
||||
|
||||
if output.status.success() {
|
||||
let stdout = String::from_utf8_lossy(&output.stdout);
|
||||
let trimmed_result = stdout.trim();
|
||||
|
||||
// For certain programs, we only want the first part before whitespace
|
||||
if self.split_whitespace {
|
||||
let parts: Vec<&str> = trimmed_result.split_whitespace().collect();
|
||||
if !parts.is_empty() {
|
||||
Ok(parts[0].to_string())
|
||||
} else {
|
||||
Ok(trimmed_result.to_string())
|
||||
}
|
||||
} else {
|
||||
Ok(trimmed_result.to_string())
|
||||
}
|
||||
} else {
|
||||
let stderr = String::from_utf8_lossy(&output.stderr);
|
||||
Err(io::Error::new(
|
||||
io::ErrorKind::Other,
|
||||
format!("Command failed: {}", stderr.trim()),
|
||||
))
|
||||
}
|
||||
} else {
|
||||
Err(io::Error::new(
|
||||
io::ErrorKind::Other,
|
||||
"No process to finalize".to_string(),
|
||||
))
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn update(&mut self, data: &[u8]) {
|
||||
|
||||
Reference in New Issue
Block a user