-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenv-inject.ps1
32 lines (28 loc) · 922 Bytes
/
env-inject.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# Load .env file and run a specified command
# Function to load .env file and set environment variables
function Load-DotEnv {
param (
[string]$envFilePath = ".env"
)
if (Test-Path $envFilePath) {
Get-Content $envFilePath | ForEach-Object {
if ($_ -match "^\s*([^#][^=]*)\s*=\s*(.*)\s*$") {
$name = $matches[1]
$value = $matches[2]
[System.Environment]::SetEnvironmentVariable($name, $value)
}
}
} else {
Write-Error "[ENV-INJECT] The .env file does not exist at path: $envFilePath"
}
}
# Load the .env file
Load-DotEnv
# Check if a command is provided as arguments
if ($args.Count -eq 0) {
Write-Host "[ENV-INJECT] No command provided. Ran as standalone script."
} else {
# Join all arguments into a single command string
$command = $args -join " "
Invoke-Expression $command
}