support editor arguments

This commit is contained in:
pacexy 2025-01-29 19:44:40 +08:00
parent 17f01e6a58
commit 20a69abfd9

View file

@ -83,7 +83,21 @@ impl Exercise {
/// Open the exercise file in the specified editor
pub fn open_in_editor(&self, editor: &str) -> io::Result<bool> {
let status = Command::new(editor).arg(self.path).status()?;
let parts: Vec<&str> = editor.split_whitespace().collect();
if parts.is_empty() {
return Ok(false);
}
let mut cmd = Command::new(parts[0]);
// If the editor command has arguments, add them to the command
if parts.len() > 1 {
cmd.args(&parts[1..]);
}
cmd.arg(self.path);
let status = cmd.status()?;
Ok(status.success())
}
}