slash-lib 0.1.0

Executor types and high-level API for the slash-command language
Documentation
use slash_lang::parser::ast::Arg;

use crate::command::{MethodDef, SlashCommand};
use crate::executor::{CommandOutput, ExecutionError, PipeValue};

/// `/read(path)` — read a file's contents to stdout.
///
/// Pure `std::fs::read`. No shell, no subprocess.
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,
        })
    }
}