hermes_runtime_components/traits/os/
exec_command.rs

1use alloc::string::String;
2
3use cgp::prelude::*;
4
5use crate::traits::fs::file_path::HasFilePathType;
6
7#[derive(Debug)]
8pub struct ExecOutput {
9    pub stdout: String,
10    pub stderr: String,
11}
12
13/// A context with capability to execute shell commands similar to shell scripts.
14/// The result of a successful execution is stored as string.
15#[derive_component(CommandExecutorComponent, CommandExecutor<Runtime>)]
16#[async_trait]
17pub trait CanExecCommand: HasFilePathType + HasErrorType {
18    async fn exec_command(
19        &self,
20        command_path: &Self::FilePath,
21        args: &[&str],
22    ) -> Result<ExecOutput, Self::Error>;
23}
24
25/// A context with capability to execute shell commands similar to shell scripts.
26/// The result of a successful execution is stored as string.
27#[derive_component(CommandWithEnvsExecutorComponent, CommandWithEnvsExecutor<Runtime>)]
28#[async_trait]
29pub trait CanExecCommandWithEnvs: HasFilePathType + HasErrorType {
30    async fn exec_command_with_envs(
31        &self,
32        command_path: &Self::FilePath,
33        args: &[&str],
34        envs: &[(&str, &str)],
35    ) -> Result<ExecOutput, Self::Error>;
36}