diff --git a/src/Repl.Core/Help/HelpTextBuilder.Rendering.cs b/src/Repl.Core/Help/HelpTextBuilder.Rendering.cs index 6f95fe6..20771b3 100644 --- a/src/Repl.Core/Help/HelpTextBuilder.Rendering.cs +++ b/src/Repl.Core/Help/HelpTextBuilder.Rendering.cs @@ -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) @@ -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[] { diff --git a/src/Repl.IntegrationTests/Given_CustomGlobalOptions.cs b/src/Repl.IntegrationTests/Given_CustomGlobalOptions.cs index 0a43035..aed9afc 100644 --- a/src/Repl.IntegrationTests/Given_CustomGlobalOptions.cs +++ b/src/Repl.IntegrationTests/Given_CustomGlobalOptions.cs @@ -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(); @@ -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] @@ -76,15 +76,15 @@ public void When_RequestingRootHelpForExplicitGlobalOption_Then_DescriptionIsLis .Options(options => options.Parsing.AddGlobalOption( "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 diff --git a/src/Repl.Tests/Given_GlobalOptionsAccessor.cs b/src/Repl.Tests/Given_GlobalOptionsAccessor.cs index 2129a3f..59b9866 100644 --- a/src/Repl.Tests/Given_GlobalOptionsAccessor.cs +++ b/src/Repl.Tests/Given_GlobalOptionsAccessor.cs @@ -67,6 +67,30 @@ public void When_OptionNotProvidedButRegisteredDefault_Then_GetValueReturnsRegis sut.GetValue("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("port"); + var sut = new GlobalOptionsSnapshot(parsing); + sut.Update(new Dictionary>(StringComparer.OrdinalIgnoreCase)); + + sut.GetValue("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("port", "Port used by the server."); + var sut = new GlobalOptionsSnapshot(parsing); + sut.Update(new Dictionary>(StringComparer.OrdinalIgnoreCase)); + + sut.GetValue("port", 8080).Should().Be(8080); + } + [TestMethod] [Description("HasValue returns false before parsing.")] public void When_NeverUpdated_Then_HasValueReturnsFalse()