Azure / azure-functions-powershell-library

MIT License
2 stars 3 forks source link

Bug bash: Parameter location is locked to param block in function #41

Open mattchenderson opened 2 years ago

mattchenderson commented 2 years ago

I was playing with parameter location for the new programming model.

This is the base I started from (which works):

function HttpTriggerMinimal { 
    [Function()] 
    param( 
        [HttpTrigger()] 
        $Request, 
        $TriggerMetadata 
    ) 

    $value = ([HttpResponseContext]@{ 
            StatusCode = [HttpStatusCode]::OK 
            Body       = 'New Programming Model rules! (Hero executed)' 
    }) 
    $value | Push-OutputBinding -Name Response 
} 

However, I don't tend to do param blocks for functions. I like having it all as part of the signature, and the opening brace '{' indicates the start of the actual function body. The following does not work, but should, I think:

function HttpTriggerMinimal(
    [HttpTrigger()] $Request,
    $TriggerMetadata
) { 
    [Function()] 

    $value = ([HttpResponseContext]@{ 
            StatusCode = [HttpStatusCode]::OK 
            Body       = 'New Programming Model rules! (Hero executed)' 
    }) 
    $value | Push-OutputBinding -Name Response 
} 

I also don't love having the attribute sitting inside the braces, and it's especially odd given that the HttpTrigger attribute is really scoped within the Function attribute, but we require the attribute within the scope, which I think is normal for PowerShell, but it feels a little odd here.

Because we're doing module stuff, I also wonder if Export-ModuleMember would be the way to handle the Function attribute injection somehow. That doesn't help with the script style of things, but there, the existing model is fine. For some reason having that within the same scope doesn't bother me as much as it does within a function definition.