[Bug] - Incorrect usage of InputObject #7691
Replies: 9 comments
-
I thinks that would be a correct way to handle this:
|
Beta Was this translation helpful? Give feedback.
-
What commands have this issue currently? |
Beta Was this translation helpful? Give feedback.
-
The input object as a whole is not handled the same way in all of our commands. There are various patterns being used to validate types or to just accept what is provided by PowerShell to that internal parameter. Are you suggesting an internal function is used to handle it all across every command? |
Beta Was this translation helpful? Give feedback.
-
Let me have a quick look and see what I find:
I think there are a lot of commands, maybe we have a look at all commands that use piped input. But we can simply change some of them if we only except $InputObject XOR the parameter. When you have a look at Add-DbaAgDatabase:
The message is already talking about XOR (because of the "either", right?), but the test does not. |
Beta Was this translation helpful? Give feedback.
-
I don't yet know. I would try to find out if other projects had a similar problem and how they've solved this. So not reinventing the wheel. As the situations and types are so different, I would rather think of some guidelines, examples and templates. Maybe start with a handful of commands and implement a solution and add a lot of documentation inside the code. Then try to get the active contributors to analyse and fix their commands. And then we have to take care of all the rest... |
Beta Was this translation helpful? Give feedback.
-
not sure if it's useful or not, but check https://github.com/sqlcollaborative/dbatools/blob/b99253a618b703c7dddf3ca10db90e3792ec9f85/functions/Get-DbaBuildReference.ps1#L116 as a way of knowing if you have something in the pipeline ^_^ |
Beta Was this translation helpful? Give feedback.
-
🚧🚨 This issue is being marked as stale due to 90 days of inactivity. If you would like this issue to remain open:
|
Beta Was this translation helpful? Give feedback.
-
I have just seen the solution in Watch-DbaXESession: We have to use the two different ParameterSetName 'instance' and 'piped'. That prevents the use of both ways to start the command. |
Beta Was this translation helpful? Give feedback.
-
I will convert this into a discussion and also close the related pull request, but leave the branch still active. |
Beta Was this translation helpful? Give feedback.
-
As this is the case in a lot of commands, I will use a general example:
The basic idea is to add the values from the named parameter to the objects that come down the pipeline.
And for some scenarios, that works:
But when more than one object is piped and the named parameter is used as well, the named parameter is processed more than once:
Beta Was this translation helpful? Give feedback.
All reactions