Skip to content

Fix global option descriptions in help output#34

Draft
carldebilly wants to merge 7 commits into
mainfrom
dev/cdb/issue-33-global-option-help
Draft

Fix global option descriptions in help output#34
carldebilly wants to merge 7 commits into
mainfrom
dev/cdb/issue-33-global-option-help

Conversation

@carldebilly

Copy link
Copy Markdown
Member

Executive Summary

Fixes #33 by carrying custom global option descriptions through registration metadata and rendering them in root help output.

Typed global options now use [Description] metadata, and manually registered global options can provide an explicit description. Root help also appends default value metadata when available.

Changes

  • Added Description to global option metadata.
  • Added optional description parameters to ParsingOptions.AddGlobalOption(...) overloads.
  • Updated UseGlobalOptions<T>() to read System.ComponentModel.DescriptionAttribute from option properties.
  • Updated root help rendering to show descriptions and [default: ...], falling back to Custom global option. only when no description exists.
  • Added integration coverage for typed descriptions, defaults, explicit descriptions, and fallback behavior.

Validation

  • dotnet test src/Repl.Tests/Repl.Tests.csproj
    • Passed: 371 tests
  • dotnet test src/Repl.IntegrationTests/Repl.IntegrationTests.csproj
    • Passed: 415 tests

autocarl

This comment was marked as resolved.

Comment thread src/Repl.Core/Help/HelpTextBuilder.Rendering.cs
@autocarl

Copy link
Copy Markdown
Contributor

I reviewed all outstanding review feedback on this PR. Public API compatibility was already addressed in e7d16a; the remaining default-value rendering scope issue is addressed by follow-up PR #41. I also created #40 for the dedicated [DefaultValue] / global option default rendering design.

@carldebilly

Copy link
Copy Markdown
Member Author

@codex Please do a full deep review here

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8f9f94b3e2

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +191 to +194
internal static string? FormatDefaultValue(object? value, Type type) =>
value is not null && !IsDefaultForType(value, type)
? value.ToString()
: null;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve explicit zero and false global defaults

When callers explicitly pass a registration default equal to the CLR default, for example AddGlobalOption<int>("port", defaultValue: 0) or AddGlobalOption<bool>("verbose", defaultValue: false), this helper returns null and discards that default. GlobalOptionsSnapshot.GetValue only applies registered defaults when definition.DefaultValue is non-null, so GetValue<int>("port", 8080) now returns the caller fallback instead of the registered 0; the previous generic overload preserved these explicit defaults. Consider separating “argument omitted” from “default(T) was supplied.”

Useful? React with 👍 / 👎.

Comment thread src/Repl.Core/ParsingOptions.cs Outdated
/// <param name="description">Optional description shown in help output.</param>
/// <param name="aliases">Optional aliases. Values without prefix are normalized to <c>--alias</c>.</param>
/// <param name="defaultValue">Optional default value metadata.</param>
public void AddGlobalOption<T>(string name, string? description, string[]? aliases = null, T? defaultValue = default) =>

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Avoid overloading the second null-accepting parameter

Adding this overload next to the existing AddGlobalOption<T>(string, string[]?, T?) makes existing consumer calls that pass a positional null for aliases, such as AddGlobalOption<string>("tenant", null), fail overload resolution because null can now mean either string? description or string[]? aliases. This is a public API, so apps using that no-alias form will stop compiling when upgrading; consider using a non-conflicting overload shape for descriptions.

Useful? React with 👍 / 👎.

The description-bearing AddGlobalOption overloads placed `description` as the
second parameter, colliding with the existing aliases-only overloads: a
positional null (e.g. `AddGlobalOption<string>("tenant", null)`) bound both
`string[]? aliases` and `string? description`, producing CS0121.

- Move `description` to a trailing required parameter on both the generic and
  type-name overloads, so existing positional-null calls keep binding the
  aliases-only overload. The original overloads are untouched (binary-safe).
- Update the two call sites that used the description overloads.
- Add a regression test asserting the positional-null call binds the
  aliases-only overload.
ParsingOptions and HelpTextBuilder each carried a copy of IsDefaultForType; the
help copy did not unwrap Nullable<T>, so the two could diverge for nullable
value-typed defaults. Route the help renderer through
ParsingOptions.IsDefaultForType and drop the duplicate.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Global option descriptions are not shown in help output

2 participants