Skip to content

Commit

Permalink
fix: error when no envVars
Browse files Browse the repository at this point in the history
  • Loading branch information
Chen1Plus committed Sep 12, 2024
1 parent ac7cc61 commit 6bb6f25
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions wmod.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ function Wmod-Load {
$env:PATH = $Path + $env:PATH

# add environment variables
$EnvVars.Keys | ForEach-Object {
New-Item -Path "Env:\$_" -Value $EnvVars[$_]
if ($EnvVars) {
$EnvVars.Keys | ForEach-Object {
New-Item -Path "Env:\$_" -Value $EnvVars[$_]
}
}

$script:Wmod_Loaded += $modulePath
Expand Down Expand Up @@ -82,8 +84,10 @@ function Unload-ByPath {
$env:PATH = $env:PATH.Replace($Path, '')

# remove environment variables
$EnvVars.Keys | ForEach-Object {
Remove-Item -Path "Env:\$_"
if ($EnvVars) {
$EnvVars.Keys | ForEach-Object {
Remove-Item -Path "Env:\$_"
}
}

$script:Wmod_Loaded = $script:Wmod_Loaded | Where-Object { $_ -ne $modulePath }
Expand Down

0 comments on commit 6bb6f25

Please sign in to comment.