-
Notifications
You must be signed in to change notification settings - Fork 21
Passing declared variables into New-Flancy -WebSchema #43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I think the only way to achieve this would be to build a dynamic script block. For example: $thing
$scriptblock = $ExecutionContext.InvokeCommand.NewScriptBlock(@"
$thing
"@)
New-Flancy -WebSchema {
Get "/" $scriptblock
} This brought up a really old memory: https://powertoe.wordpress.com/2010/02/10/dynamic-code-in-powershell/ |
It might be interesting to use a scriptblock property with some sort of variable list property that we interpret and inject vars from the current session, but then again, doing it the PS way with NewScriptBlock() is probably the better way to do this. |
I tried this: $text = "Hello world"
$sb = $ExecutionContext.InvokeCommand.NewScriptBlock(@"
$text
"@)
New-Flancy -url http://localhost:8002 -webschema @(
Get "/" {
$sb
}
) and when I go to the url, the page is blank. |
tired it like this as well: $text = "Hello world"
$sb = $ExecutionContext.InvokeCommand.NewScriptBlock(@"
$text
"@)
New-Flancy -url http://localhost:8002 -webschema @(
Get "/" $sb
) still blank. |
That's probably because Hello world isn't a function or anything. If you want to return it, you'd need to do this $sb = $ExecutionContext.InvokeCommand.NewScriptBlock(@"
"$text"
"@) You can always test the code locally too: See if that works |
This may not be possible but it would be nice if variables could be passed in the -WebSchema parameter of New-Flancy:
The only reason I did this was because things like $PSScriptRoot don't seem to exist in the scope of those cmd blocks.
The text was updated successfully, but these errors were encountered: