-
Notifications
You must be signed in to change notification settings - Fork 407
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
Add ParameterSet "Now-Table" and making ParameterSets clearer #580
Conversation
…rns "Supply values for the following parameters: ExcelPackage:"
@jhoneill review? I'm planning to publish v6 tomorrow, Friday. No rush on this, prefer to wait. Does the |
Same Problem on 6.2
|
followed by either |
I also tried to figure it out but failed, I hope that they will add the option to provide an array of "Default" parameter sets to be evaluated in the provided order, and not just one DefaultParameterSetName. that will make situations like this much simpler. Edit. Looks like that when the pipeline is used it always go to the set with the mandatory parameter, which is the less preferable option usually as it's the opposite of what it dose when the pipeline is not used. function Test-It
{
Param(
[Parameter(ParameterSetName = 'A')]
$A,
[Parameter(ParameterSetName = 'B', Mandatory)]
$B,
[Parameter(ValueFromPipeline = $true)]
$InputObject
)
$PSCmdlet.ParameterSetName
}
# This will select set A automatically.
Test-It -InputObject 0
# This will select set B and ask you for input.
0 | Test-It Adding the function Test-It
{
Param(
[Parameter(ParameterSetName = 'A')]
$A,
[Parameter(ParameterSetName = 'B', Mandatory, ValueFromPipelineByPropertyName)]
$B,
[Parameter(ValueFromPipeline = $true)]
$InputObject
)
$PSCmdlet.ParameterSetName
}
# This will select set A automatically.
Test-It -InputObject 0
# This will select set A automatically.
0 | Test-It So this is essentially what I did. I digged in the commits and saw that you @jhoneill was the one that come up with the |
I just want to mention that non of the problems addressed in this PR are braking the functionality of the module, this is just to make the module more user friendly and behave consistently mostly for new users. |
@ili101 see https://jamesone111.wordpress.com/2016/11/30/powershell-piped-parameter-peculiarities-and-a-palliative-pattern/ for background on using ValueFromPipelineByPropertyName As that says ... it seems that when you are not piping anything, PowerShell is happy to decide parameter sets based on the absence of a mandatory parameter. When you are piping it stops doing that, but ValueFromPipelineByPropertyName seems to put it back. I don't properly understand it, but I've found it fixes some cases. |
Now I have had a chance to look at this more I'm finding some problems. So I'd stick to just a parameter set to allow now and tables. @dfinke Your call, but we could solve this by just getting rid of the parameter sets for table vs AutoFilter, and then have |
a404a4a
to
84df072
Compare
Pushed a quick test removing the Table ParameterSets and all the ValueFromPipelineByPropertyName, could be good. |
Was implemented in #590 👍 |
Thanks for closing. |
Before we had the default parameter set "Default" that meant if there where 0 parameters it's "Now" and if there is more it's "Path".
After the update "Default" meant "Now" always except when "Path" is set, making "New" the DefaultParameterSet in practice but not actually the DefaultParameterSetName in code.
That can be a little confusing for example in

Show-Command
if the user will select "Default" but will get different behaviors if he fills -Path or not ("New" behavior if not and "Default" behavior if -Path used)Also parameter set "New-Table" was missing so you can do
Export-Excel -TableName 'Table'
to get -Now behavior but if you explicitly do the same thingExport-Excel -TableName 'Table' -Now
you will get an error that "Parameter set cannot be resolved"So I made the "Now" parameter set set the default, this should not change anything but make it more clear if you are using "Now" or not in

Show-Command
Also I added the missing "New-Table" parameter set.
While Writing this I found a problem:
$DataTable | Export-Excel -TableName 'Table'
is not working, it returns "Supply values for the following parameters: ExcelPackage:" So I workaround it, I reported this to the PowerShell team last year but there is no response yet PowerShell/PowerShell#8516