@@ -44,6 +44,13 @@ impl TreeExitCodeCell {
4444 }
4545}
4646
47+ /// Shell options that can be set via `set -o` / `set +o`.
48+ #[ derive( Clone , Default ) ]
49+ pub struct ShellOptions {
50+ /// When enabled, pipeline exit code is the rightmost non-zero exit code.
51+ pub pipefail : bool ,
52+ }
53+
4754#[ derive( Clone ) ]
4855pub struct ShellState {
4956 /// Environment variables that should be passed down to sub commands
@@ -54,6 +61,7 @@ pub struct ShellState {
5461 shell_vars : HashMap < OsString , OsString > ,
5562 cwd : PathBuf ,
5663 commands : Rc < HashMap < String , Rc < dyn ShellCommand > > > ,
64+ options : ShellOptions ,
5765 kill_signal : KillSignal ,
5866 process_tracker : ChildProcessTracker ,
5967 tree_exit_code_cell : TreeExitCodeCell ,
@@ -74,6 +82,7 @@ impl ShellState {
7482 shell_vars : Default :: default ( ) ,
7583 cwd : PathBuf :: new ( ) ,
7684 commands : Rc :: new ( commands) ,
85+ options : Default :: default ( ) ,
7786 kill_signal,
7887 process_tracker : ChildProcessTracker :: new ( ) ,
7988 tree_exit_code_cell : Default :: default ( ) ,
@@ -94,6 +103,17 @@ impl ShellState {
94103 & self . env_vars
95104 }
96105
106+ pub fn options ( & self ) -> & ShellOptions {
107+ & self . options
108+ }
109+
110+ pub fn set_option ( & mut self , name : & str , value : bool ) {
111+ match name {
112+ "pipefail" => self . options . pipefail = value,
113+ _ => { } // ignore unknown options
114+ }
115+ }
116+
97117 pub fn get_var ( & self , name : & OsStr ) -> Option < & OsString > {
98118 let name = if cfg ! ( windows) {
99119 Cow :: Owned ( name. to_ascii_uppercase ( ) )
@@ -138,6 +158,9 @@ impl ShellState {
138158 EnvChange :: Cd ( new_dir) => {
139159 self . set_cwd ( new_dir. clone ( ) ) ;
140160 }
161+ EnvChange :: SetOption ( name, value) => {
162+ self . set_option ( name, * value) ;
163+ }
141164 }
142165 }
143166
@@ -222,6 +245,8 @@ pub enum EnvChange {
222245 // `unset ENV_VAR`
223246 UnsetVar ( OsString ) ,
224247 Cd ( PathBuf ) ,
248+ // `set -o OPTION` or `set +o OPTION`
249+ SetOption ( String , bool ) ,
225250}
226251
227252pub type FutureExecuteResult = LocalBoxFuture < ' static , ExecuteResult > ;
0 commit comments