1use crate::{Command, Output, Error};
2use russh::{Channel, ChannelId, ChannelMsg, client::Msg};
3use core::future::Future;
4
5pub trait HandleProcessExt {
6 fn channel_open_exec_spawn(&self, command: Vec<u8>) -> impl Future<Output=Result<Command<Msg>, Error>> + Send;
7 fn channel_open_exec_output(&self, command: Vec<u8>) -> impl Future<Output=Result<Output, Error>> + Send
8 where Self: Sync
9 {
10 Box::pin(async move {
11 let command = self.channel_open_exec_spawn(command).await?;
12 command.output().await
13 })
14 }
15}
16
17impl<H> HandleProcessExt for russh::client::Handle<H>
18where H: russh::client::Handler
19{
20 fn channel_open_exec_spawn(&self, command: Vec<u8>) -> impl Future<Output=Result<Command<Msg>, Error>> + Send {
21 async move {
22 Ok(Command::from_channel(self.channel_open_session().await?, command))
23 }
24 }
25}