Skip to content

Commit 19d8ec3

Browse files
author
James Brundage
committed
feat: Language.Templates/Function.ByInputType ( Fixes #843 )
1 parent 5f1d829 commit 19d8ec3

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<#
2+
.SYNOPSIS
3+
Gets Language Functions by Input Type
4+
.DESCRIPTION
5+
Returns a dictionary of all unique language functions that accept a pipeline parameter.
6+
7+
The key will be the type of parameter accepted.
8+
The value will be a list of commands that accept that parameter from the pipeline.
9+
.NOTES
10+
Primitive parameter types and string types will be ignored.
11+
#>
12+
param()
13+
# We want the results to be ordered (both the keys and the values)
14+
$byInputType = [Ordered]@{}
15+
$uniqueList = @($this.Unique | Sort-Object Order)
16+
foreach ($uniqueCommand in $uniqueList) {
17+
, @(foreach ($parameterSet in $uniqueCommand.ParameterSets) {
18+
foreach ($parameterInSet in $parameterSet.Parameters) {
19+
if (-not $parameterInSet.ValueFromPipeline) { continue }
20+
if ($parameterInSet.ParameterType.IsPrimitive) { continue }
21+
if ($parameterInSet.ParameterType -eq [string]) { continue }
22+
if (-not $byInputType[$parameterInSet.ParameterType]) {
23+
$byInputType[$parameterInSet.ParameterType] = [Collections.Generic.List[PSObject]]::new()
24+
}
25+
$byInputType[$parameterInSet.ParameterType].Add($uniqueCommand)
26+
}
27+
})
28+
}
29+
$byInputType
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<#
2+
.SYNOPSIS
3+
Gets Language Templates by Input Type
4+
.DESCRIPTION
5+
Returns a dictionary of all unique language templates that accept a pipeline parameter.
6+
7+
The key will be the type of parameter accepted.
8+
The value will be a list of commands that accept that parameter from the pipeline.
9+
.NOTES
10+
Primitive parameter types and string types will be ignored.
11+
#>
12+
param()
13+
# We want the results to be ordered (both the keys and the values)
14+
$byInputType = [Ordered]@{}
15+
$uniqueList = @($this.Unique | Sort-Object Order)
16+
foreach ($uniqueCommand in $uniqueList) {
17+
, @(foreach ($parameterSet in $uniqueCommand.ParameterSets) {
18+
foreach ($parameterInSet in $parameterSet.Parameters) {
19+
if (-not $parameterInSet.ValueFromPipeline) { continue }
20+
if ($parameterInSet.ParameterType.IsPrimitive) { continue }
21+
if ($parameterInSet.ParameterType -eq [string]) { continue }
22+
if (-not $byInputType[$parameterInSet.ParameterType]) {
23+
$byInputType[$parameterInSet.ParameterType] = [Collections.Generic.List[PSObject]]::new()
24+
}
25+
$byInputType[$parameterInSet.ParameterType].Add($uniqueCommand)
26+
}
27+
})
28+
}
29+
$byInputType

0 commit comments

Comments
 (0)