-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Add a -splat common parameter #10984
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
Conversation
|
I see a couple of issues with this approach. First, I think this breaks a common scenario: sleep -s 10Basically any command that has exactly 1 parameter beginning with Second, a common parameter would also not work with non-cmdlet binding functions because common parameters are not added to those functions. I think it would be a mistake to introduce an alternative syntax for splatting that doesn't work everywhere, especially when the incorrect syntax might appear to work silently as is typically the case where |
This comment has been minimized.
This comment has been minimized.
|
@KirkMunro, successfully started retry of |
There were never any guarantees with non-alias shorthand for parameter names that such syntax will continue to work over time. Only parameter aliases can guarantee consistent syntax, and commands where it is very common to use that syntax would be better off assigning those aliases so that they do continue to work over time. For the specific scenario mentioned here, we can add a Don't get me wrong...I get the concern -- there is muscle memory to think about. That said though, shorthand parameter names don't always work from version to version because parameters are added to commands over time. I also recognize that this is a common parameter, so more invasive, vs. a command author adding a parameter and thinking to add aliases to support specific shorthand syntax as they add that parameter. The guarantee still isn't there though, unless aliases are used.
You're right that this wouldn't work for basic functions. A rule should be added to PSSA to pick up on such things and warn users. If there isn't a rule already to identify when a basic function is passed common parameters, there should be, regardless of what happens with this PR. Your argument about common parameters appearing to work silently with |
This comment has been minimized.
This comment has been minimized.
|
@KirkMunro, successfully started retry of |
This comment has been minimized.
This comment has been minimized.
|
@KirkMunro, successfully started retry of |
|
The only concern that I have is the name |
|
We could opt for something like |
While I like the sound of it, I think Since the concept of splatting already needs to be learned, I like the explicit nature of the |
|
I should note, I did consider including |
|
How about |
This comment has been minimized.
This comment has been minimized.
|
@KirkMunro, successfully started retry of |
|
What about |
|
List is a type, that might be confusing. PS seems a bit redundant and not common for parameter names |
|
We keep having discussions in various threads when adding common parameters how not to clobber existing parameters. It could have been avoided if a reserved prefix was used, like with cmdlets. It's slightly off topic for this specific PR but wanted to bring it up for the overall common parameter discussion. |
|
This pull request has been automatically marked as Review Needed because it has been there has not been any activity for 7 days. |
|
Closing. |
|
no -splat, no -@, no @@ yet, will there be anything like that in the future? It seems like all approaches to improve splatting and thus usability are declined. Is there anything else in the work? |
PR Summary
Similar to #10073, this PR enhances the splat functionality that is available in PowerShell. Instead of doing this by extending operators, this PR adds a common
-splatparameter of type[IDictionary[]]that supports the following new features:The functionality in this PR is only available if you have the
PSCommonSplatParameterexperimental feature enabled.PR Context
This PR helps because it extends splatting to support quite a few features that were requested by the community and described in RFC0002, which can currently be found here. Specifically, this allows users to use inline splatting of literal hashtables, variables, properties, the result of methods, or the result of commands.
I have opened this PR to offer an alternative syntax to the syntax offered in #10073 while also supporting a broader set of scenarios necessary for easier splatting in scripts.
Here are some examples demonstrating how this can be used:
PR Checklist
.h,.cpp,.cs,.ps1and.psm1files have the correct copyright headerWIP:or[ WIP ]to the beginning of the title (theWIPbot will keep its status check atPendingwhile the prefix is present) and remove the prefix when the PR is ready.PSCommonSplatParameter- Enabling this feature will make the-splatcommon parameter available to end users.