use slash_lang::parser::ast::Arg;
use crate::command::{MethodDef, SlashCommand};
use crate::executor::{CommandOutput, ExecutionError, PipeValue};
pub struct Read;
impl SlashCommand for Read {
fn name(&self) -> &str {
"read"
}
fn methods(&self) -> &[MethodDef] {
&[]
}
fn execute(
&self,
primary: Option<&str>,
_args: &[Arg],
_input: Option<&PipeValue>,
) -> Result<CommandOutput, ExecutionError> {
let path = primary.ok_or_else(|| {
ExecutionError::Runner("/read requires a path: /read(file.txt)".into())
})?;
let content = std::fs::read(path)
.map_err(|e| ExecutionError::Runner(format!("/read({}): {}", path, e)))?;
Ok(CommandOutput {
stdout: Some(content),
stderr: None,
success: true,
})
}
}