1
1
use std:: ffi:: OsStr ;
2
2
use std:: path:: Path ;
3
- use std:: process:: { Command , CommandArgs , CommandEnvs , ExitStatus , Output } ;
3
+ use std:: process:: { Command , CommandArgs , CommandEnvs , ExitStatus , Output , Stdio } ;
4
4
5
5
/// What should be done when the command fails.
6
6
#[ derive( Debug , Copy , Clone ) ]
@@ -13,19 +13,30 @@ pub enum BehaviorOnFailure {
13
13
Ignore ,
14
14
}
15
15
16
- /// How should the output of the command be handled (whether it should be captured or printed).
16
+ /// How should the output of a specific stream of the command (stdout/stderr) be handled
17
+ /// (whether it should be captured or printed).
17
18
#[ derive( Debug , Copy , Clone ) ]
18
19
pub enum OutputMode {
19
- /// Prints the stdout/stderr of the command to stdout/stderr of bootstrap (by inheriting these
20
- /// streams).
21
- /// Corresponds to calling `cmd.status()`.
20
+ /// Prints the stream by inheriting it from the bootstrap process.
22
21
Print ,
23
- /// Captures the stdout and stderr of the command into memory.
24
- /// Corresponds to calling `cmd.output()`.
25
- CaptureAll ,
26
- /// Captures the stdout of the command into memory, inherits stderr.
27
- /// Corresponds to calling `cmd.output()`.
28
- CaptureStdout ,
22
+ /// Captures the stream into memory.
23
+ Capture ,
24
+ }
25
+
26
+ impl OutputMode {
27
+ pub fn captures ( & self ) -> bool {
28
+ match self {
29
+ OutputMode :: Print => false ,
30
+ OutputMode :: Capture => true ,
31
+ }
32
+ }
33
+
34
+ pub fn stdio ( & self ) -> Stdio {
35
+ match self {
36
+ OutputMode :: Print => Stdio :: inherit ( ) ,
37
+ OutputMode :: Capture => Stdio :: piped ( ) ,
38
+ }
39
+ }
29
40
}
30
41
31
42
/// Wrapper around `std::process::Command`.
@@ -45,7 +56,8 @@ pub enum OutputMode {
45
56
pub struct BootstrapCommand {
46
57
pub command : Command ,
47
58
pub failure_behavior : BehaviorOnFailure ,
48
- pub output_mode : OutputMode ,
59
+ pub stdout : OutputMode ,
60
+ pub stderr : OutputMode ,
49
61
// Run the command even during dry run
50
62
pub run_always : bool ,
51
63
}
@@ -113,14 +125,14 @@ impl BootstrapCommand {
113
125
self
114
126
}
115
127
116
- /// Capture the output of the command, do not print it.
128
+ /// Capture all output of the command, do not print it.
117
129
pub fn capture ( self ) -> Self {
118
- Self { output_mode : OutputMode :: CaptureAll , ..self }
130
+ Self { stdout : OutputMode :: Capture , stderr : OutputMode :: Capture , ..self }
119
131
}
120
132
121
133
/// Capture stdout of the command, do not print it.
122
134
pub fn capture_stdout ( self ) -> Self {
123
- Self { output_mode : OutputMode :: CaptureStdout , ..self }
135
+ Self { stdout : OutputMode :: Capture , ..self }
124
136
}
125
137
}
126
138
@@ -137,7 +149,8 @@ impl From<Command> for BootstrapCommand {
137
149
Self {
138
150
command,
139
151
failure_behavior : BehaviorOnFailure :: Exit ,
140
- output_mode : OutputMode :: Print ,
152
+ stdout : OutputMode :: Print ,
153
+ stderr : OutputMode :: Print ,
141
154
run_always : false ,
142
155
}
143
156
}
0 commit comments