-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Auto-enable DOTNET_CLI_CONTEXT_VERBOSE for diagnostic verbosity #52222
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: release/10.0.2xx
Are you sure you want to change the base?
Auto-enable DOTNET_CLI_CONTEXT_VERBOSE for diagnostic verbosity #52222
Conversation
Co-authored-by: marcpopMSFT <12663534+marcpopMSFT@users.noreply.github.com>
…n access Co-authored-by: marcpopMSFT <12663534+marcpopMSFT@users.noreply.github.com>
Co-authored-by: marcpopMSFT <12663534+marcpopMSFT@users.noreply.github.com>
|
@copilot a solution that requires every command to remember to call some method is not workable - instead you should use the Doing this keeps the behavior consistent across all commands that use the verbosity. |
Per @baronfel's feedback, moved verbosity handling to an Action on the VerbosityOption itself. This eliminates the need for each command to manually call ApplyVerbosityOptions(). The Action is attached to all VerbosityOption variants and will be invoked by System.CommandLine when the option is parsed. Changes: - Added ApplyVerbosityAction class in CommonOptions - Added Action property to all VerbosityOption definitions - Reverted all command-specific verbosity handling code - Kept IsDiagnostic() extension method for reuse Co-authored-by: baronfel <573979+baronfel@users.noreply.github.com>
I've refactored the implementation to use the Option Action pattern as you suggested. The ApplyVerbosityAction is now attached to all VerbosityOption definitions in CommonOptions, and all the per-command calls have been reverted (commit 47b9106). However, I'm finding that the Action doesn't appear to be invoked during testing. Could you clarify when System.CommandLine invokes Option Actions? Is there something specific I need to do to ensure the Action is called when the option is parsed? |
The Action needs Terminating = false so that command execution continues after the action runs. Verified that DOTNET_CLI_CONTEXT_VERBOSE is now properly set to "True" when using -v diag or -v diagnostic across build, restore, and other commands. Co-authored-by: baronfel <573979+baronfel@users.noreply.github.com>
- Removed commented debug statements - Simplified success case in enum parsing - All functionality remains working as verified by tests Co-authored-by: baronfel <573979+baronfel@users.noreply.github.com>
|
@copilot the 'pre-actions' are collected during parsing here, and then invoked sequentially during command invocation here. your implementation of the action needs to change slightly - you don't need to do all of this work to get the verbosity, you can just directly fetch the value from the parse result. If the action is being invoked you can assume that the verbosity is in the parse result. if you pass a reference to the verbosity option to the Action, then you can do something like |
Per @baronfel's feedback, refactored ApplyVerbosityAction to accept the verbosity option as a constructor parameter. This allows direct use of parseResult.GetValue(verbosityOption) instead of searching through all children. Changes: - Made ApplyVerbosityAction generic to handle both VerbosityOptions and VerbosityOptions? types - Pass option reference to Action constructor - Simplified Invoke logic to directly get value from parse result - Changed HiddenVerbosityOption from field to property to support proper initialization with Action Verified working with dotnet build/restore -v diag Co-authored-by: baronfel <573979+baronfel@users.noreply.github.com>
Updated the implementation to pass the option reference to the Action as you suggested (commit e7a82e7). The Action now uses |
baronfel
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This LGTM - the CI failure is the WinRT known issue
Implementation Complete
The solution uses System.CommandLine's Option Action mechanism with a generic Action class that receives the option reference directly. This allows cleaner code using
parseResult.GetValue(verbosityOption)as suggested by @baronfel.Verified working:
dotnet build -v diag✓dotnet restore -v diagnostic✓dotnet build -v normal(does not set variable) ✓Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.