use std::time::Duration;
use super::{
output_collector::collect_output,
output_reader::OutputReader,
stdin_writer::StdinWriter,
};
use crate::{
CommandError,
CommandOutput,
};
pub(crate) struct CommandIo {
stdout_reader: OutputReader,
stderr_reader: OutputReader,
stdin_writer: StdinWriter,
}
impl CommandIo {
pub(crate) fn new(
stdout_reader: OutputReader,
stderr_reader: OutputReader,
stdin_writer: StdinWriter,
) -> Self {
Self {
stdout_reader,
stderr_reader,
stdin_writer,
}
}
pub(crate) fn is_finished(&self) -> bool {
self.stdout_reader.is_finished()
&& self.stderr_reader.is_finished()
&& self
.stdin_writer
.as_ref()
.is_none_or(std::thread::JoinHandle::is_finished)
}
pub(crate) fn collect(
self,
command: &str,
status: std::process::ExitStatus,
elapsed: Duration,
) -> Result<CommandOutput, CommandError> {
collect_output(
command,
status,
elapsed,
self.stdout_reader,
self.stderr_reader,
self.stdin_writer,
)
}
}