Skip to content
Open
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
20 changes: 18 additions & 2 deletions src/MamlWriter/MamlHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,24 @@ private static SyntaxItem ConvertSyntax(Model.SyntaxItem syntax)

private static PipelineInputType GetPipelineInputType(Model.Parameter parameter)
{
var pipelineInput = PipelineInputType.None;

bool byValue = parameter.ParameterSets.Any(ps => ps.ValueFromPipeline);
bool byPropertyName = parameter.ParameterSets.Any(ps => ps.ValueFromPipelineByPropertyName);

if (byValue && byPropertyName)
{
pipelineInput = PipelineInputType.ByValue | PipelineInputType.ByPropertyName;
}
else if (byValue)
{
pipelineInput = PipelineInputType.ByValue;
}
else if (byPropertyName)
{
pipelineInput = PipelineInputType.ByPropertyName;
}

var pipelineInput = new PipelineInputType();
return pipelineInput;
}

Expand All @@ -192,6 +208,7 @@ private static Parameter ConvertParameter(Model.Parameter parameter)
var pSet = parameter.ParameterSets.FirstOrDefault();
newParameter.Position = pSet is null ? Model.Constants.NamedString : pSet.Position;
newParameter.Value = GetParameterValue(parameter);
newParameter.SupportsPipelineInput = GetPipelineInputType(parameter);

if (parameter.Description is not null)
{
Expand Down Expand Up @@ -259,4 +276,3 @@ private static CommandDetails ConvertCommandDetails(CommandHelp commandHelp)

}
}

24 changes: 8 additions & 16 deletions src/MamlWriter/Parameter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,30 +50,22 @@ public class Parameter
/// Can the parameter accept its value from the pipeline?
/// </summary>
/// <remarks>
/// Either "true (ByValue)", "true (ByPropertyName)", or "false".
/// Either "true (ByValue)", "true (ByPropertyName)", "true (ByValue, ByPropertyName)", or "false".
/// </remarks>
[XmlAttribute("pipelineInput")]
public string PipelineInputString
{
set { throw new System.NotImplementedException(); }
get
{
if (SupportsPipelineInput == PipelineInputType.ByValue && SupportsPipelineInput == PipelineInputType.ByPropertyName)
return SupportsPipelineInput switch
{
return "true (ByValue, ByPropertyName)";
}
else if (SupportsPipelineInput == PipelineInputType.ByValue)
{
return "true (ByValue)";
}
else if (SupportsPipelineInput == PipelineInputType.ByPropertyName)
{
return "true (ByPropertyName)";
}
else
{
return "false";
}
PipelineInputType.None => "false",
PipelineInputType.ByValue => "true (ByValue)",
PipelineInputType.ByPropertyName => "true (ByPropertyName)",
PipelineInputType.ByValueAndByPropertyName => "true (ByValue, ByPropertyName)",
_ => "false"
};
}
}

Expand Down
8 changes: 7 additions & 1 deletion src/MamlWriter/PipelineInputType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ public enum PipelineInputType
/// Parameter can take its value from a property of the same name on objects in the pipeline.
/// </summary>
[XmlEnum("true (ByPropertyName)")]
ByPropertyName = 2
ByPropertyName = 2,

/// <summary>
/// Parameter can take its value from the pipeline both by value and by property name.
/// </summary>
[XmlEnum("true (ByValue, ByPropertyName)")]
ByValueAndByPropertyName = ByValue | ByPropertyName
}
}
7 changes: 6 additions & 1 deletion test/Pester/Cmdlet.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,11 @@ Describe "Miscellaneous cmdlet tests" {
$help.name | Should -BeExactly "Get-ChildItem"
}


It "Should have correct ByValue and ByPropertyName for the Path parameter" {
$help = Show-HelpPreview -Path $mamlPath
$param = $help.parameters.parameter | Where-Object -Property Name -EQ "Path"
$param | Should -Not -BeNullOrEmpty
$param.pipelineInput | Should -Be "true (ByValue, ByPropertyName)"
}
}
}