Skip to content

CLI: Normalize bool option action invoking#53872

Merged
baronfel merged 6 commits intodotnet:mainfrom
MiYanni:OptionActionsCleanup
Apr 28, 2026
Merged

CLI: Normalize bool option action invoking#53872
baronfel merged 6 commits intodotnet:mainfrom
MiYanni:OptionActionsCleanup

Conversation

@MiYanni
Copy link
Copy Markdown
Member

@MiYanni MiYanni commented Apr 14, 2026

Related: fc3ce47

Summary

From the OTel changes un-revert, it seems that I missed there is an extension method we made, HasOption, that does the same check I was doing by-hand. It is in a different project, Microsoft.DotNet.Cli.CommandLine, which is why I missed it. I also realized that all the bool option actions should do this check anyway.

This means:

  • They all check if the actual option was passed on the CLI
  • They all check if the value of the option is true (for bool, it defaults to false)
    • Technically, there could be a DefaultValueFactory defined that would change this behavior.

The actual way to do all this better is to actually change these options to be defined as a new type of option; something that doesn't contain a backing Argument (thus, no value type). Meaning, make something like FlagOption that only cares if it was provided on the CLI or not. But that would be a bigger endeavor.

Copilot AI review requested due to automatic review settings April 14, 2026 22:50
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR normalizes how boolean option actions are invoked in the dotnet CLI by ensuring they only run when the option was explicitly provided on the command line and evaluates to true.

Changes:

  • Updates several option action classes to accept Option<bool> and gate execution on parseResult.HasOption(...) and the option’s parsed boolean value.
  • Replaces the diagnostic option precedence check to use the action’s bound Option (instead of hard-coding Parser.RootCommand.DiagOption).
  • Adds the required Microsoft.DotNet.Cli.CommandLine using for the HasOption extension.

Comment thread src/Cli/dotnet/ParserOptionActions.cs
@baronfel baronfel merged commit 2d77a61 into dotnet:main Apr 28, 2026
24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants