PowerShell / PowerShell/PowerShell
Splatting for native commands results in incompatible syntax for modern commands
@SeeminglyScience is already working on this.
Since Nov 14, 2023.
- Dominant language
- C#
- Stars
- 55.5k
- Forks
- 8.5k
- Avg merge
- 1d 2h
- Merged PRs (30d)
- 88
Description
Summary of the new feature / enhancement
Since PS5.1, splatting to a native commands results in a single - prefix and a : separator between the parameter name and the parameter value.
$a = @{a=1;bb=2}
echoit @a
Expected where the convention is a single character parameter is prefixed by a single dash and a spelled out parameter is prefixed by two dashes and parameter values are space separated:
echoit -a 1 --bb 2
Actual:
echoit -a:1 -bb:2
The current behavior means this doesn't work with most modern commands. If the hashtable is converted to an array, you can get some of the right behavior as splatting an array always means separate parameters and prefixes need to be defined within the array.
Proposed technical implementation details (optional)
If we are ok with a breaking change as it could be a bucket 3 item, then we use the logic that single character parameters are prefixed by single dash while multi-character parameter names are prefixed by a double-dash.
If we need to support -, --, /, etc... explicitly as well as :,=, etc.. separator, then we could have a predefined special member of the hashtable that defines those options:
$params = @{
_prefix = '/'
_separator = '='
arg1 = 1
arg2 = 2
}
I'm choosing the underscore so it minimizes conflicts with existing parameter names. There is a discovery problem that can only be solved by docs or a feedbackprovider that sees splatting and the native command failing and pointing to the docs.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.