@@ -22,10 +22,8 @@ pub mod cwdsource;
2222pub mod filesource;
2323mod homethunk;
2424pub mod terminalsource;
25- pub mod varsource;
2625
2726use cwdsource:: * ;
28- use varsource:: * ;
2927
3028use crate :: utils:: tty:: { stderr_isatty, stdout_isatty} ;
3129
@@ -64,11 +62,11 @@ use crate::utils::tty::{stderr_isatty, stdout_isatty};
6462/// methods are in performance critical loops (except perhaps progress bars -
6563/// and even there we should be doing debouncing and managing update rates).
6664#[ enum_dispatch]
67- pub trait CurrentProcess : CurrentDirSource + VarSource + Debug { }
65+ pub trait CurrentProcess : CurrentDirSource + Debug { }
6866
6967/// Allows concrete types for the currentprocess abstraction.
7068#[ derive( Clone , Debug ) ]
71- #[ enum_dispatch( CurrentProcess , CurrentDirSource , VarSource ) ]
69+ #[ enum_dispatch( CurrentProcess , CurrentDirSource ) ]
7270pub enum Process {
7371 OSProcess ( OSProcess ) ,
7472 #[ cfg( feature = "test" ) ]
@@ -89,6 +87,25 @@ impl Process {
8987 . map ( String :: from)
9088 }
9189
90+ pub fn var ( & self , key : & str ) -> Result < String , env:: VarError > {
91+ match self {
92+ Process :: OSProcess ( _) => env:: var ( key) ,
93+ #[ cfg( feature = "test" ) ]
94+ Process :: TestProcess ( p) => match p. vars . get ( key) {
95+ Some ( val) => Ok ( val. to_owned ( ) ) ,
96+ None => Err ( env:: VarError :: NotPresent ) ,
97+ } ,
98+ }
99+ }
100+
101+ pub ( crate ) fn var_os ( & self , key : & str ) -> Option < OsString > {
102+ match self {
103+ Process :: OSProcess ( _) => env:: var_os ( key) ,
104+ #[ cfg( feature = "test" ) ]
105+ Process :: TestProcess ( p) => p. vars . get ( key) . map ( OsString :: from) ,
106+ }
107+ }
108+
92109 pub ( crate ) fn args ( & self ) -> Box < dyn Iterator < Item = String > + ' _ > {
93110 match self {
94111 Process :: OSProcess ( _) => Box :: new ( env:: args ( ) ) ,
0 commit comments