Skip to content

Commit d7a9fa8

Browse files
authored
Invoke-Formatter: Accept input from pipeline (#1763)
* Invoke-Formatter: Accept input from pipeline * other params as well
1 parent 33c5ffa commit d7a9fa8

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

Engine/Commands/InvokeFormatterCommand.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@ public class InvokeFormatterCommand : PSCmdlet, IOutputWriter
2525
///
2626
/// *NOTE*: Unlike ScriptBlock parameter, the ScriptDefinition parameter require a string value.
2727
/// </summary>
28-
[ParameterAttribute(Mandatory = true, Position = 1)]
28+
[ParameterAttribute(Mandatory = true, ValueFromPipeline = true, ValueFromPipelineByPropertyName = true, Position = 1)]
2929
[ValidateNotNull]
3030
public string ScriptDefinition { get; set; }
3131

3232
/// <summary>
3333
/// A settings hashtable or a path to a PowerShell data file (.psd1) file that contains the settings.
3434
/// </summary>
35-
[Parameter(Mandatory = false, Position = 2)]
35+
[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, Position = 2)]
3636
[ValidateNotNull]
3737
public object Settings { get; set; } = defaultSettingsPreset;
3838

@@ -44,7 +44,7 @@ public class InvokeFormatterCommand : PSCmdlet, IOutputWriter
4444
/// end column number. These numbers must be greater than 0.
4545
/// </summary>
4646
/// <returns></returns>
47-
[Parameter(Mandatory = false, Position = 3)]
47+
[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, Position = 3)]
4848
[ValidateNotNull]
4949
[ValidateCount(4, 4)]
5050
public int[] Range { get; set; }

Tests/Engine/InvokeFormatter.tests.ps1

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,19 @@ Describe "Invoke-Formatter Cmdlet" {
1414
}
1515
}
1616

17+
Context 'Accept Value from Pipeline' {
18+
It 'Value from Pipeline' {
19+
'foo' | Invoke-Formatter | Should -Be 'foo'
20+
}
21+
It 'Value from Pipeline by Property Name with just the mandatory ScriptDefinition parameter' {
22+
[pscustomobject]@{ 'ScriptDefinition' = 'foo' } | Invoke-Formatter | Should -Be 'foo'
23+
}
24+
It 'Value from Pipeline by Property Name with all parameters' {
25+
[pscustomobject]@{ ScriptDefinition = 'foo'; Settings = @(); Range = 1, 1, 1, 4 } |
26+
Invoke-Formatter | Should -Be 'foo'
27+
}
28+
}
29+
1730
Context "When positional parameters are given" {
1831
It "Should use the positional parameters" {
1932
$def = @"

0 commit comments

Comments
 (0)