Skip to content
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

Invoke-Formatter: Accept input from pipeline #1763

Merged
merged 3 commits into from
Aug 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Engine/Commands/InvokeFormatterCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ public class InvokeFormatterCommand : PSCmdlet, IOutputWriter
///
/// *NOTE*: Unlike ScriptBlock parameter, the ScriptDefinition parameter require a string value.
/// </summary>
[ParameterAttribute(Mandatory = true, Position = 1)]
[ParameterAttribute(Mandatory = true, ValueFromPipeline = true, ValueFromPipelineByPropertyName = true, Position = 1)]
[ValidateNotNull]
public string ScriptDefinition { get; set; }

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

Expand All @@ -44,7 +44,7 @@ public class InvokeFormatterCommand : PSCmdlet, IOutputWriter
/// end column number. These numbers must be greater than 0.
/// </summary>
/// <returns></returns>
[Parameter(Mandatory = false, Position = 3)]
[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, Position = 3)]
[ValidateNotNull]
[ValidateCount(4, 4)]
public int[] Range { get; set; }
Expand Down
13 changes: 13 additions & 0 deletions Tests/Engine/InvokeFormatter.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,19 @@ Describe "Invoke-Formatter Cmdlet" {
}
}

Context 'Accept Value from Pipeline' {
It 'Value from Pipeline' {
'foo' | Invoke-Formatter | Should -Be 'foo'
}
It 'Value from Pipeline by Property Name with just the mandatory ScriptDefinition parameter' {
[pscustomobject]@{ 'ScriptDefinition' = 'foo' } | Invoke-Formatter | Should -Be 'foo'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
[pscustomobject]@{ 'ScriptDefinition' = 'foo' } | Invoke-Formatter | Should -Be 'foo'
[pscustomobject]@{ 'ScriptDefinition' = 'command1;command2' } | Invoke-Formatter | Should -Be 'command1; command2'

}
It 'Value from Pipeline by Property Name with all parameters' {
[pscustomobject]@{ ScriptDefinition = 'foo'; Settings = @(); Range = 1, 1, 1, 4 } |
Invoke-Formatter | Should -Be 'foo'
}
}

Context "When positional parameters are given" {
It "Should use the positional parameters" {
$def = @"
Expand Down