Skip to content
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
26 changes: 21 additions & 5 deletions src/Repl.Core/Help/HelpTextBuilder.Rendering.cs
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,27 @@ private static Type UnwrapAsyncReturnType(Type returnType)

private static bool IsDefaultForType(object value, Type type)
{
return ParsingOptions.IsDefaultForType(value, type);
if (type == typeof(bool))
{
return value is false;
}

if (type == typeof(int))
{
return value is 0;
}

if (type == typeof(long))
{
return value is 0L;
}

if (type == typeof(double))
{
return value is 0.0d;
}

return false;
}

private static string ResolveOptionPlaceholder(Type parameterType)
Expand Down Expand Up @@ -605,10 +625,6 @@ private static string[][] BuildGlobalOptionRows(ParsingOptions parsingOptions)
var description = string.IsNullOrWhiteSpace(option.Description)
? "Custom global option."
: option.Description;
if (!string.IsNullOrWhiteSpace(option.DefaultValue))
{
description = $"{description} [default: {option.DefaultValue}]";
}

return new[]
{
Expand Down
14 changes: 7 additions & 7 deletions src/Repl.IntegrationTests/Given_CustomGlobalOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ public void When_RequestingRootHelp_Then_CustomGlobalOptionIsListedInGlobalOptio
}

[TestMethod]
[Description("Regression guard: verifies typed global option descriptions and defaults are rendered in root help.")]
public void When_RequestingRootHelpForTypedGlobalOptions_Then_DescriptionsAndDefaultsAreListed()
[Description("Regression guard: verifies typed global option descriptions are rendered in root help without adding default-value display.")]
public void When_RequestingRootHelpForTypedGlobalOptions_Then_DescriptionsAreListed()
{
var sut = ReplApp.Create()
.UseGlobalOptions<DemoGlobals>();
Expand All @@ -62,10 +62,10 @@ public void When_RequestingRootHelpForTypedGlobalOptions_Then_DescriptionsAndDef

output.ExitCode.Should().Be(0);
output.Text.Should().Contain("--tenant, -t");
output.Text.Should().Contain("Tenant id used for all commands. [default: default]");
output.Text.Should().Contain("Tenant id used for all commands.");
output.Text.Should().Contain("--verbose, -v");
output.Text.Should().Contain("Enable verbose diagnostics for all commands.");
output.Text.Should().NotContain("Enable verbose diagnostics for all commands. [default: False]");
output.Text.Should().NotContain("[default:");
}

[TestMethod]
Expand All @@ -76,15 +76,15 @@ public void When_RequestingRootHelpForExplicitGlobalOption_Then_DescriptionIsLis
.Options(options => options.Parsing.AddGlobalOption<string>(
"tenant",
description: "Tenant id used for all commands.",
aliases: ["-t"],
defaultValue: "default"));
aliases: ["-t"]));
sut.Map("ping", () => "ok");

var output = ConsoleCaptureHelper.Capture(() => sut.Run(["--help", "--no-logo"]));

output.ExitCode.Should().Be(0);
output.Text.Should().Contain("--tenant, -t");
output.Text.Should().Contain("Tenant id used for all commands. [default: default]");
output.Text.Should().Contain("Tenant id used for all commands.");
output.Text.Should().NotContain("[default:");
}

private sealed class DemoGlobals
Expand Down
24 changes: 24 additions & 0 deletions src/Repl.Tests/Given_GlobalOptionsAccessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,30 @@ public void When_OptionNotProvidedButRegisteredDefault_Then_GetValueReturnsRegis
sut.GetValue<int>("port").Should().Be(3000);
}

[TestMethod]
[Description("GetValue returns caller default when a value-typed option has no explicit registration default.")]
public void When_ValueTypeOptionNotProvidedAndNoRegisteredDefault_Then_GetValueReturnsCallerDefault()
{
var parsing = new ParsingOptions();
parsing.AddGlobalOption<int>("port");
var sut = new GlobalOptionsSnapshot(parsing);
sut.Update(new Dictionary<string, IReadOnlyList<string>>(StringComparer.OrdinalIgnoreCase));

sut.GetValue<int>("port", 8080).Should().Be(8080);
}

[TestMethod]
[Description("GetValue returns caller default when a described value-typed option has no explicit registration default.")]
public void When_DescribedValueTypeOptionNotProvidedAndNoRegisteredDefault_Then_GetValueReturnsCallerDefault()
{
var parsing = new ParsingOptions();
parsing.AddGlobalOption<int>("port", "Port used by the server.");
var sut = new GlobalOptionsSnapshot(parsing);
sut.Update(new Dictionary<string, IReadOnlyList<string>>(StringComparer.OrdinalIgnoreCase));

sut.GetValue<int>("port", 8080).Should().Be(8080);
}

[TestMethod]
[Description("HasValue returns false before parsing.")]
public void When_NeverUpdated_Then_HasValueReturnsFalse()
Expand Down
Loading