Skip to content
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,14 @@ internal static IEnumerable<ExtendedTypeDefinition> GetFormatData()
"System.Management.Automation.Job",
ViewsOf_System_Management_Automation_Job());

yield return new ExtendedTypeDefinition(
"Microsoft.PowerShell.Commands.TextMeasureInfo",
ViewsOf_Deserialized_Microsoft_PowerShell_Commands_TextMeasureInfo());

yield return new ExtendedTypeDefinition(
"Microsoft.PowerShell.Commands.GenericMeasureInfo",
ViewsOf_Deserialized_Microsoft_PowerShell_Commands_GenericMeasureInfo());

yield return new ExtendedTypeDefinition(
"Deserialized.Microsoft.PowerShell.Commands.TextMeasureInfo",
ViewsOf_Deserialized_Microsoft_PowerShell_Commands_TextMeasureInfo());
Expand Down Expand Up @@ -1062,11 +1070,11 @@ private static IEnumerable<FormatViewDefinition> ViewsOf_Deserialized_Microsoft_
ListControl.Create()
.StartEntry()
.AddItemProperty(@"Count")
.AddItemProperty(@"Average")
.AddItemProperty(@"Sum")
.AddItemProperty(@"Maximum")
.AddItemProperty(@"Minimum")
.AddItemProperty(@"Property")
.AddItemPropertyIfSet(@"Average")
.AddItemPropertyIfSet(@"Sum")
.AddItemPropertyIfSet(@"Maximum")
.AddItemPropertyIfSet(@"Minimum")
.AddItemPropertyIfSet(@"Property")
.EndEntry()
.EndList());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -788,6 +788,24 @@ public DisplayEntry(string value, DisplayEntryValueType type)
ValueType = type;
}

/// <summary>
/// Creates a DisplayEntry for the given scriptblock.
/// </summary>
/// <param name="scriptblock">The content of the scriptblock</param>
public static DisplayEntry CreateScriptBlockEntry(string scriptblock)
{
return new DisplayEntry(scriptblock, DisplayEntryValueType.ScriptBlock);
}

/// <summary>
/// Creates a DisplayEntry for the given property name.
/// </summary>
/// <param name="property">the name of the property</param>
public static DisplayEntry CreatePropertyEntry(string property)
{
return new DisplayEntry(property, DisplayEntryValueType.Property);
}

/// <summary/>
public override string ToString()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ internal ListEntryBuilder(ListControlBuilder listBuilder, ListControlEntry listE
_listEntry = listEntry;
}

private ListEntryBuilder AddItem(string value, string label, DisplayEntryValueType kind, string format)
private ListEntryBuilder AddItem(string value, string label, DisplayEntryValueType kind, string format, DisplayEntry itemSelectionContition)
{
if (string.IsNullOrEmpty(value))
throw PSTraceSource.NewArgumentNullException("property");
Expand All @@ -379,22 +379,30 @@ private ListEntryBuilder AddItem(string value, string label, DisplayEntryValueTy
{
DisplayEntry = new DisplayEntry(value, kind),
Label = label,
FormatString = format
FormatString = format,
ItemSelectionCondition = itemSelectionContition,
});

return this;
}

/// <summary></summary>
public ListEntryBuilder AddItemScriptBlock(string scriptBlock, string label = null, string format = null)
public ListEntryBuilder AddItemScriptBlock(string scriptBlock, string label = null, string format = null, DisplayEntry itemSelectionContition = null)
{
return AddItem(scriptBlock, label, DisplayEntryValueType.ScriptBlock, format);
return AddItem(scriptBlock, label, DisplayEntryValueType.ScriptBlock, format, itemSelectionContition);
}

/// <summary></summary>
public ListEntryBuilder AddItemProperty(string property, string label = null, string format = null)
public ListEntryBuilder AddItemProperty(string property, string label = null, string format = null, DisplayEntry itemSelectionContition = null)
Copy link
Collaborator

Choose a reason for hiding this comment

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

The same.

{
return AddItem(property, label, DisplayEntryValueType.Property, format);
return AddItem(property, label, DisplayEntryValueType.Property, format, itemSelectionContition);
}

/// <summary></summary>
public ListEntryBuilder AddItemPropertyIfSet(string property, string label = null, string format = null)
{
var itemSelectionContition = DisplayEntry.CreatePropertyEntry(property);
return AddItem(property, label, DisplayEntryValueType.Property, format, itemSelectionContition);
}

/// <summary></summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -883,6 +883,11 @@ private void LoadListControlItemDefinitionsFromObjectModel(ListControlEntryDefin
fpt.expression = expression;
fpt.fieldFormattingDirective.formatString = listItem.FormatString;
lvid.formatTokenList.Add(fpt);
if (listItem.ItemSelectionCondition != null)
{
var conditionToken = LoadExpressionFromObjectModel(listItem.ItemSelectionCondition, viewIndex, typeName);
lvid.conditionToken = conditionToken;
}
}

if (!String.IsNullOrEmpty(listItem.Label))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,5 +98,13 @@ Describe "Object cmdlets" -Tags "CI" {
$gmi = "abc",[Datetime]::Now | measure -sum -max -ev err -ea silentlycontinue
$gmi.Count | Should Be 2
}

It 'should only display fields that are set' {
$text = 1, 2, 3 | Measure-Object -Sum -Average | Format-List | Out-String
$text -match "min|max" | Should -BeFalse
Copy link
Collaborator

@JamesWTruher JamesWTruher Feb 28, 2018

Choose a reason for hiding this comment

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

would it be better if this was a positive test? What should this actually look like? or both positive/negative?


$text = 1, 2, 3 | Measure-Object -Minimum -Maximum | Format-List | Out-String
$text -match "min|max" | Should -BeTrue
}
}
}