Skip to content

Make defaults available to command validators - #2861

Open
zjdangge wants to merge 1 commit into
dotnet:mainfrom
zjdangge:codex/validator-default-values
Open

zjdangge wants to merge 1 commit into
dotnet:mainfrom
zjdangge:codex/validator-default-values

Conversation

@zjdangge

Copy link
Copy Markdown

Command validators currently run before results are created for omitted options and arguments with default values. Calling GetValue from a validator therefore returns the type's default (for example, 0) instead of the configured DefaultValueFactory value.

Create implicit default results for the selected command and its ancestors before running command validators. The factories are still evaluated on demand and cached by the existing conversion path. Validator ordering and the behavior of invalid explicit inputs are unchanged. Results are not created for unselected commands.

Fixes #2841.

Tests cover default and explicit option values, defaults inherited from a parent command, argument defaults, dependencies between defaults, implicit-result flags, and factory evaluation boundaries. Four regression cases failed before the fix. The Windows Debug solution build completed with no warnings or errors, and all five test assemblies passed: 1,957 passed, 14 existing skips, including the main suites on .NET 10 and .NET Framework 4.7.2. Release, Linux, and macOS were not run locally.

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.

Command validators don't seem to use the default value factory of an Option

1 participant