@@ -23,10 +23,8 @@ pub mod cwdsource;
2323pub mod filesource;
2424mod homethunk;
2525pub mod terminalsource;
26- pub mod varsource;
2726
2827use cwdsource:: * ;
29- use varsource:: * ;
3028
3129/// An abstraction for the current process.
3230///
@@ -63,11 +61,11 @@ use varsource::*;
6361/// methods are in performance critical loops (except perhaps progress bars -
6462/// and even there we should be doing debouncing and managing update rates).
6563#[ enum_dispatch]
66- pub trait CurrentProcess : CurrentDirSource + VarSource + Debug { }
64+ pub trait CurrentProcess : CurrentDirSource + Debug { }
6765
6866/// Allows concrete types for the currentprocess abstraction.
6967#[ derive( Clone , Debug ) ]
70- #[ enum_dispatch( CurrentProcess , CurrentDirSource , VarSource ) ]
68+ #[ enum_dispatch( CurrentProcess , CurrentDirSource ) ]
7169pub enum Process {
7270 OSProcess ( OSProcess ) ,
7371 #[ cfg( feature = "test" ) ]
@@ -88,6 +86,25 @@ impl Process {
8886 . map ( String :: from)
8987 }
9088
89+ pub fn var ( & self , key : & str ) -> Result < String , env:: VarError > {
90+ match self {
91+ Process :: OSProcess ( _) => env:: var ( key) ,
92+ #[ cfg( feature = "test" ) ]
93+ Process :: TestProcess ( p) => match p. vars . get ( key) {
94+ Some ( val) => Ok ( val. to_owned ( ) ) ,
95+ None => Err ( env:: VarError :: NotPresent ) ,
96+ } ,
97+ }
98+ }
99+
100+ pub ( crate ) fn var_os ( & self , key : & str ) -> Option < OsString > {
101+ match self {
102+ Process :: OSProcess ( _) => env:: var_os ( key) ,
103+ #[ cfg( feature = "test" ) ]
104+ Process :: TestProcess ( p) => p. vars . get ( key) . map ( OsString :: from) ,
105+ }
106+ }
107+
91108 pub ( crate ) fn args ( & self ) -> Box < dyn Iterator < Item = String > + ' _ > {
92109 match self {
93110 Process :: OSProcess ( _) => Box :: new ( env:: args ( ) ) ,
0 commit comments