1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
use super::AsyncStdChild;
use crate::AsyncStdGlobalRuntime;
use arta::process::{ProcessRuntime, RuntimeCommand};
use futures::prelude::Future;
use std::{
    ffi::OsStr,
    path::Path,
    process::{ExitStatus, Output, Stdio},
};

/// Async-std specific [`RuntimeCommand`] implementation.
pub struct AsyncStdCommand {
    inner: async_std::process::Command,
}

impl RuntimeCommand for AsyncStdCommand {
    type Runtime = AsyncStdGlobalRuntime;

    fn new(program: impl AsRef<OsStr>) -> Self
    where
        Self: Sized,
    {
        Self {
            inner: async_std::process::Command::new(program),
        }
    }

    fn arg(&mut self, arg: impl AsRef<OsStr>) -> &mut Self {
        self.inner.arg(arg);
        self
    }

    fn args(&mut self, args: impl Iterator<Item = impl AsRef<OsStr>>) -> &mut Self {
        self.inner.args(args);
        self
    }

    fn env(&mut self, key: impl AsRef<OsStr>, value: impl AsRef<OsStr>) -> &mut Self {
        self.inner.env(key, value);
        self
    }

    fn envs(
        &mut self,
        vars: impl Iterator<Item = (impl AsRef<OsStr>, impl AsRef<OsStr>)>,
    ) -> &mut Self {
        self.inner.envs(vars);
        self
    }

    fn env_remove(&mut self, key: impl AsRef<OsStr>) -> &mut Self {
        self.inner.env_remove(key);
        self
    }

    fn env_clear(&mut self) -> &mut Self {
        self.inner.env_clear();
        self
    }

    fn current_dir(&mut self, dir: impl AsRef<Path>) -> &mut Self {
        self.inner.current_dir(dir);
        self
    }

    fn stdin(&mut self, stdin: impl Into<Stdio>) -> &mut Self {
        self.inner.stdin(stdin);
        self
    }

    fn stdout(&mut self, stdout: impl Into<Stdio>) -> &mut Self {
        self.inner.stdout(stdout);
        self
    }

    fn stderr(&mut self, stderr: impl Into<Stdio>) -> &mut Self {
        self.inner.stderr(stderr);
        self
    }

    fn spawn(&mut self) -> std::io::Result<<Self::Runtime as ProcessRuntime>::Child> {
        self.inner
            .spawn()
            .map(|child| AsyncStdChild { inner: child })
    }

    fn output(&mut self) -> impl Future<Output = std::io::Result<Output>> + Send {
        self.inner.output()
    }

    fn status(&mut self) -> impl Future<Output = std::io::Result<ExitStatus>> + Send {
        self.inner.status()
    }

    #[cfg(unix)]
    fn uid(&mut self, uid: u32) -> &mut Self {
        use async_std::os::unix::process::CommandExt;

        self.inner.uid(uid);
        self
    }

    #[cfg(unix)]
    fn gid(&mut self, gid: u32) -> &mut Self {
        use async_std::os::unix::process::CommandExt;

        self.inner.gid(gid);
        self
    }

    #[cfg(unix)]
    unsafe fn pre_exec(
        &mut self,
        f: impl FnMut() -> std::io::Result<()> + Send + Sync + 'static,
    ) -> &mut Self {
        use async_std::os::unix::process::CommandExt;

        self.inner.pre_exec(f);
        self
    }

    #[cfg(windows)]
    fn creation_flags(&mut self, flags: u32) -> &mut Self {
        use async_std::os::windows::process::CommandExt;

        self.inner.creation_flags(flags);
        self
    }
}