Last active
July 15, 2016 15:24
-
-
Save onyxhat/d69bde514e3fc68b693e71b738731be9 to your computer and use it in GitHub Desktop.
Stub for parsing Chocolatey --params string into variables in the chocolateyinstall.ps1/chocolateyuninstall.ps1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#$packageParameters = $env:chocolateyPackageParameters | |
$packageParameters = "var1 = val1;var2=`"val2 with spaces -`"" | |
$match_pattern = "(?<key>(\w+))\s*=\s*(?<value>([`"'])?([\w- _\\:\.]+)([`"'])?)" | |
# Now parse the packageParameters using good old regular expression | |
if ($packageParameters -match $match_pattern ) { | |
$results = $packageParameters | Select-String $match_pattern -AllMatches | |
$results.matches | % { | |
Set-Variable -Name $_.Groups['key'].Value.Trim() -Value $_.Groups['value'].Value.Trim() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment