Skip to content
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

Incremental Dynamic Parameter Bind #361

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

dkattan
Copy link

@dkattan dkattan commented Oct 19, 2023

Summary

  1. Incremental Binding: As RuntimeDefinedParameter objects are written to the output in the dynamicparam block, they are immediately bound if an argument is available. This behavior differs from the current state, where all parameters are bound after the entire dynamicparam block has executed.

  2. Variable Creation: When a RuntimeDefinedParameter is bound, a variable with the name of that parameter should be created in the dynamicparam block scope. This makes the bound value immediately available for subsequent logic in the dynamicparam block.

I already have a PR with the required code changes: PowerShell/PowerShell#20069
 

Example

For brevity, this example assumes a user-supplied New-Parameter function.

Function Get-EdgeUpdates
{
    param()
    dynamicparam
    {   
        $EdgeVersions = Invoke-RestMethod https://edgeupdates.microsoft.com/api/products
        # Emit a RuntimeDefinedParameter to the pipeline
        New-Parameter -Name Product -ValidValues $EdgeVersions.Product -Type ([string]) -Mandatory
        # $Product is immediately available for use
        if($Product)
        {
            $EdgeReleases = $EdgeVersions | ?{$_.Product -eq $Product} | select -Expand Releases # Beta,Stable,Dev,Canary
            New-Parameter -Name Platform -ValidValues ($EdgeReleases.Platform | select -Unique) -Type ([string]) -Mandatory # Windows,Linux,MacOS,Android
            if($Platform)
            {
                $EdgeReleases = $EdgeReleases | ?{$_.Platform -eq $Platform}                
                New-Parameter -Name Architecture -ValidValues ($EdgeReleases.Architecture | select -Unique) -Type ([string]) -Mandatory # x86,x64,arm64,universal
                if($Architecture)
                {
                    $EdgeReleases = $EdgeReleases | ?{$_.Architecture -eq $Architecture}                
                    New-Parameter -Name Version -ValidValues ($EdgeReleases.ProductVersion | select -Unique) -Type ([string]) -Mandatory    
                }
            }
        }
    }
    end
    {
    }
}

@dkattan dkattan changed the title Real-Time Dynamic Parameter Bind Incremental Dynamic Parameter Bind Oct 19, 2023
@dkattan
Copy link
Author

dkattan commented Nov 17, 2023

@SydneyhSmith When do things like this get reviewed? I would love to be part of the conversation.

@SteveL-MSFT SteveL-MSFT added the WG-Engine core PowerShell engine, interpreter, and runtime label Jan 18, 2024
@SteveL-MSFT
Copy link
Member

@JamesWTruher can you see if the Engine WG can review this?

@dkattan
Copy link
Author

dkattan commented Jan 18, 2024

@JamesWTruher can you see if the Engine WG can review this?

I'd really love to be a part of the conversation with the working group. This is a non-breaking change, only net new functionality but the last time they reviewed it I was told to create an RFC so I did.

@dkattan
Copy link
Author

dkattan commented Feb 14, 2024

@SteveL-MSFT Community call is tomorrow, still looking for feedback on this.

@IntegriComCalvin
Copy link

I would really really like to have this feature. So much easier to write and I have several use cases.

@homotechsual
Copy link

Would love to see this in PowerShell it would open up some interesting and more complex use cases not possible with the current implementation.

@gigacodedev
Copy link

I could definitely find use in this, seems useful for complex multi-site automation tasks that may have a varying set of environments.

@noaht8um
Copy link

+1. Have some existing modules that use dynamic parameters which would be streamlined with this. This would also open the door for less confusion when it comes to writing user-driven PowerShell modules (i.e. a helper module for technical folks that are not necessarily PowerShell savvy). This would be awesome.

@dszp
Copy link

dszp commented Feb 21, 2024

+1 This would make it substantially easier to deal with situations such as the example, which likely has equal application in dealing with the mess of versions and channels of Office/Apps for Business/Enterprise besides Edge, in another Microsoft example.

This would be helpful in automating both with larger scripting toolsets and in adding better validation to more complex system admin and management scripts, so I support the change.

@immolate
Copy link

Anything Darren writes generally makes my life easier as one of his customers. Please consider the changes and merge so many, MANY people can benefit from his recommendations. Thanks.

@Dakota-LM
Copy link

I think this will add a lot of incentive for people to jump on dynamicparams. Currently, they don't seem to be as robust as one would assume for something called "dynamicparams".

@MWGMorningwood
Copy link

I think this will add a lot of incentive for people to jump on dynamicparams. Currently, they don't seem to be as robust as one would assume for something called "dynamicparams".

I 100% agree with this- it seems like Darren is the one trying to make the name true here

@etopple
Copy link

etopple commented Feb 25, 2024

I’d love to see this pushed into production. Would be super helpful.

@dimitrirodis
Copy link

So, net new functionality with no breaking changes. Sounds like a win. What's the problem?

@jbbehar
Copy link

jbbehar commented Feb 26, 2024

Agree with all the above comments - can this be prioritized for inclusion ASAP? This PR is already months old.

@JerBar
Copy link

JerBar commented Feb 27, 2024

This would be a huge game changer for sure.

@andrewqit
Copy link

Add one more to the list that needs this!

@tylernocwing
Copy link

I hope this gets implemented dkattan

@herringms
Copy link

Very needed for partners

@dlfoster311
Copy link

I think this would be a cool addition! It could make scripts way smarter by adapting on the fly as you define parameters.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
WG-Engine core PowerShell engine, interpreter, and runtime
Projects
None yet
Development

Successfully merging this pull request may close these issues.