Add shlex

This commit is contained in:
mo8it
2026-04-06 16:58:15 +02:00
parent dace3e3953
commit b48663030b
4 changed files with 22 additions and 6 deletions
+12 -5
View File
@@ -5,6 +5,7 @@ use std::{
};
use anyhow::{Context, Result, bail};
use shlex::Shlex;
mod zellij;
@@ -34,20 +35,26 @@ pub enum Editor {
}
impl Editor {
pub fn new(cmd: Option<String>) -> Option<Self> {
pub fn new(cmd: Option<String>) -> Result<Option<Self>> {
if env::var_os("TERM_PROGRAM").is_some_and(|v| v == "vscode") {
return Some(Self::VSCode);
return Ok(Some(Self::VSCode));
}
if let Some(cmd) = cmd {
todo!()
let shlex = &mut Shlex::new(&cmd);
let program = shlex.next().context("Program missing in `--edit-cmd`")?;
let args = shlex.collect();
if shlex.had_error {
bail!("Failed to parse the command in `--edit-cmd`");
}
return Ok(Some(Self::Cmd(program, args)));
}
if env::var_os("ZELLIJ").is_some() {
return Some(Self::Zellij(None));
return Ok(Some(Self::Zellij(None)));
}
None
Ok(None)
}
pub fn open(
+2 -1
View File
@@ -60,10 +60,11 @@ fn main() -> Result<ExitCode> {
bail!(FORMAT_VERSION_HIGHER_ERR);
}
let editor = Editor::new(args.edit_cmd)?;
let (mut app_state, state_file_status) = AppState::new(
info_file.exercises,
info_file.final_message.unwrap_or_default(),
Editor::new(args.edit_cmd),
editor,
)?;
// Show the welcome message if the state file doesn't exist yet.