conch_runtime_pshaw/spawn/ast_impl/
command.rs

1use crate::env::LastStatusEnvironment;
2use crate::error::RuntimeError;
3use crate::{ExitStatus, Spawn, EXIT_ERROR};
4use conch_parser::ast;
5use futures_core::future::BoxFuture;
6
7impl<T, E> Spawn<E> for ast::Command<T>
8where
9    T: Spawn<E>,
10    T::Error: From<RuntimeError>,
11    E: Send + ?Sized + LastStatusEnvironment,
12{
13    type Error = T::Error;
14
15    fn spawn<'life0, 'life1, 'async_trait>(
16        &'life0 self,
17        env: &'life1 mut E,
18    ) -> BoxFuture<'async_trait, Result<BoxFuture<'static, ExitStatus>, Self::Error>>
19    where
20        'life0: 'async_trait,
21        'life1: 'async_trait,
22        Self: 'async_trait,
23    {
24        match self {
25            ast::Command::List(list) => list.spawn(env),
26            ast::Command::Job(_) => {
27                Box::pin(async move {
28                    // FIXME: eventual job control would be nice
29                    env.set_last_status(EXIT_ERROR);
30                    Err(T::Error::from(RuntimeError::Unimplemented(
31                        "job control is not currently supported",
32                    )))
33                })
34            }
35        }
36    }
37}