github.com/upcmd/up@v0.8.1-0.20230108151705-ad8b797bf04f/tests/functests/c0193.yml (about) 1 doc_meta: | 2 folder: env-vars 3 title: virtualEnv cmd 4 head: | 5 This introduces a cmd virtualEnv to manage the shell execution enviornment, which you can source shell script/file, you can take a snapshot and save the current enviornment as a named venv, and you can also restore your shell environment from the saved venv 6 7 8 sections: 9 - title: Demo 10 log: yes 11 12 - title: Demo 13 content: | 14 15 params: 16 name: the venv name 17 action: snapshot | restore 18 source: the source content 19 srcfiles: a list of file to source 20 21 rules: 22 23 * source and srcfiles can not coexit but require at least one of them 24 * source and srcfiles are not required if you just want to save current shell session 25 * name and action can be both non exist or must both exist 26 27 tasks: 28 29 - 30 name: task 31 desc: | 32 please switch to use case1|case2 ... 33 the reason we do not chain all cases together is because 34 the venv will pollute the entire running session unless you mananage to restore it 35 task: 36 - 37 func: call 38 do: case3 39 40 - 41 name: case1 42 desc: | 43 task: 44 - 45 func: shell 46 desc: | 47 before sourcing, the env var: AAA does not exist 48 this will cause an error 49 do: 50 - env |grep AAA 51 flags: 52 - ignoreError 53 54 - 55 func: cmd 56 desc: | 57 case1: only source 58 source via the source content 59 do: 60 - name: virtualEnv 61 cmd: 62 source: | 63 echo "start of source" 64 export AAA=sourced_aaa 65 echo "end of source" 66 67 - 68 func: shell 69 desc: | 70 after sourcing, the env var: AAA exist 71 do: 72 - env |grep AAA 73 74 - 75 name: case2 76 desc: | 77 task: 78 - 79 func: shell 80 desc: | 81 before sourcing, the env var: AAA does not exist 82 this will cause an error 83 do: 84 - env |grep AAA 85 flags: 86 - ignoreError 87 88 - 89 func: cmd 90 desc: | 91 case2: only source 92 source via srcfile 93 do: 94 - name: virtualEnv 95 cmd: 96 srcfile: ./tests/functests/test_env.rc 97 - 98 func: shell 99 desc: | 100 after sourcing, the env var: AAA exist 101 do: 102 - env |grep AAA 103 104 - 105 name: case3 106 desc: | 107 task: 108 - 109 func: shell 110 desc: | 111 before sourcing, the env var: AAA does not exist 112 this will cause an error 113 do: 114 - env |grep AAA 115 flags: 116 - ignoreError 117 118 - 119 func: cmd 120 desc: | 121 no source/srcfile input 122 with name and action 123 now it will save current shell env 124 which has got no AAA in it 125 do: 126 - name: virtualEnv 127 cmd: 128 name: venv0 129 action: snapshot 130 131 - 132 func: shell 133 desc: | 134 since there is no source, this will still cause an error 135 do: 136 - env |grep AAA 137 flags: 138 - ignoreError 139 140 - 141 func: cmd 142 desc: | 143 now source and save current shell environment variables 144 do: 145 - name: virtualEnv 146 cmd: 147 name: venv1 148 action: snapshot 149 srcfile: ./tests/functests/test_env.rc 150 151 - 152 func: shell 153 desc: | 154 after sourcing, the env var: AAA exist 155 the error should be cleared 156 do: 157 - env |grep AAA 158 159 - 160 func: cmd 161 desc: | 162 now let's restore to the point of venv0 163 which has got no AAA in it 164 do: 165 - name: virtualEnv 166 cmd: 167 name: venv0 168 action: restore 169 170 - 171 func: shell 172 desc: | 173 this will still cause an error 174 as now the shell env is restored to venv0 175 which has got no AAA in it 176 do: 177 - env |grep AAA 178 flags: 179 - ignoreError 180 181 - 182 func: cmd 183 desc: | 184 now let's restore to the point of venv1 185 which has got AAA in it 186 we expect the error is clear 187 do: 188 - name: virtualEnv 189 cmd: 190 name: venv1 191 action: restore 192 193 - 194 func: shell 195 desc: | 196 after sourcing, the env var: AAA exist 197 the error should be cleared 198 do: 199 - env |grep AAA 200 201 - 202 name: case4 203 desc: | 204 task: 205 206 - 207 func: cmd 208 desc: | 209 source via the source content 210 do: 211 - name: virtualEnv 212 cmd: 213 source: | 214 echo "start of source" 215 export AAA=sourced_aaa 216 echo "end of source" 217 218 - 219 func: shell 220 desc: | 221 after sourcing, the env var: AAA exist 222 do: 223 - env |grep AAA 224 225 - 226 func: cmd 227 desc: | 228 if you use pure param 229 it will unset all env vars from the current execution context 230 do: 231 - name: virtualEnv 232 cmd: 233 action: pure 234 235 - 236 func: shell 237 desc: | 238 before sourcing, the env var: AAA does not exist 239 this will cause an error 240 do: 241 - env |grep AAA 242 flags: 243 - ignoreError