1use std::path::PathBuf;
2
3use thiserror::Error;
4
5#[derive(Debug, Clone, Copy, PartialEq, Eq)]
6pub enum StreamKind {
7 Stdout,
8 Stderr,
9}
10
11impl StreamKind {
12 pub fn as_str(self) -> &'static str {
13 match self {
14 Self::Stdout => "stdout",
15 Self::Stderr => "stderr",
16 }
17 }
18}
19
20#[derive(Debug, Clone, PartialEq, Eq)]
21pub struct StreamEvent {
22 pub stream: StreamKind,
23 pub line: Vec<u8>,
24}
25
26#[derive(Debug, Clone, PartialEq, Eq)]
27pub enum ReadStatus<T> {
28 Line(T),
29 Timeout,
30 Eof,
31}
32
33#[derive(Debug, Error)]
34pub enum ProcessError {
35 #[error("process already started")]
36 AlreadyStarted,
37 #[error("process is not running")]
38 NotRunning,
39 #[error("process stdin is not available")]
40 StdinUnavailable,
41 #[error("failed to spawn process: {0}")]
42 Spawn(std::io::Error),
43 #[error("failed to read process output: {0}")]
44 Io(std::io::Error),
45 #[error("process timed out")]
46 Timeout,
47}
48
49#[derive(Debug, Clone)]
50pub enum CommandSpec {
51 Shell(String),
52 Argv(Vec<String>),
53}
54
55#[derive(Debug, Clone, Copy, PartialEq, Eq)]
56pub enum StdinMode {
57 Inherit,
58 Piped,
59 Null,
60}
61
62#[derive(Debug, Clone, Copy, PartialEq, Eq)]
63pub enum StderrMode {
64 Stdout,
65 Pipe,
66}
67
68#[derive(Debug, Clone)]
69pub struct ProcessConfig {
70 pub command: CommandSpec,
71 pub cwd: Option<PathBuf>,
72 pub env: Option<Vec<(String, String)>>,
73 pub capture: bool,
74 pub stderr_mode: StderrMode,
75 pub creationflags: Option<u32>,
76 pub create_process_group: bool,
77 pub stdin_mode: StdinMode,
78 pub nice: Option<i32>,
79}