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

Table dynamic params do not pull default values #22

Open
insomniacc opened this issue Mar 12, 2023 · 2 comments
Open

Table dynamic params do not pull default values #22

insomniacc opened this issue Mar 12, 2023 · 2 comments
Assignees
Labels
enhancement New feature or request

Comments

@insomniacc
Copy link
Owner

insomniacc commented Mar 12, 2023

I'll explain with a possible use case:
Get-SNOWObject is used as a template function for all other Get-SNOW* (table) commands.
It's parameters are pulled through to form the framework of those other functions (into the dynamic param block)
Default values are not pulled through as it's not part of the 'Get-Command' dataset.

Now lets say that by default, we wanted all Get-SNOW* functions to default the -DisplayValue to 'true'.
I could set this in the Get-SNOWObject command, but it would not apply to all others templating from this.

Possible Solution:
Ast parsing

This is not currently presenting an issue, although might be a nice to have for the use case specified above.

@insomniacc insomniacc added the enhancement New feature or request label Mar 12, 2023
@insomniacc
Copy link
Owner Author

This might also be a better method for parsing the script block pushed into Invoke-SNOWBatch, rather than using the current regex method. It's something to explore anyway.

@insomniacc insomniacc added the scoping A potential idea that needs to be scoped out first to understand if it's feasible label Mar 12, 2023
@insomniacc insomniacc removed the scoping A potential idea that needs to be scoped out first to understand if it's feasible label Mar 23, 2023
@insomniacc insomniacc added this to the 1.0.1 milestone Mar 26, 2023
@insomniacc insomniacc self-assigned this Mar 26, 2023
@insomniacc insomniacc modified the milestones: 1.0.1, 1.1.0 Mar 27, 2023
@insomniacc
Copy link
Owner Author

insomniacc commented Apr 3, 2023

I've tested Import-DefaultParamSet with the following additional code:

$Parsed = [System.Management.Automation.Language.Parser]::ParseInput($BaseCommand.Definition,[ref]$null,[ref]$null)
$ParsedParams = $parsed.FindAll({$args[0] -is [System.Management.Automation.Language.ParameterAst]},$true)

Within the section that loops through the get-command $BaseCommand.Parameters, I'm also doing the following:

$ParsedParam = $null
$ParsedParam = $ParsedParams.Where({$_.Name.ToString() -eq "`$$key"})
if($ParsedParam -and $null -ne $ParsedParam.DefaultValue){
    $param.Value = $ParsedParam.DefaultValue.Value
}

Unfortunately using this method the default value that's being defined is not available to use.
I found a similar issue here https://stackoverflow.com/questions/11012514/how-to-set-default-value-for-dynamic-param
$PSBoundParameters was used as a workaround.
This would not work in this instance since it's nested inside a helper function.

I'm not sure if there's an alternative on how to do this in the way that I'm hoping for, but for now I don't have a specific requirement that needs this, it would just be a nice to have. Going to stick it on the back burner until either something new comes up or I decide to shelve it.

@insomniacc insomniacc removed this from the 1.1.0 milestone Apr 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant