33
44using System . CommandLine ;
55using System . CommandLine . Invocation ;
6- using System . CommandLine . Parsing ;
7- using Microsoft . DotNet . Cli . Extensions ;
86using Microsoft . DotNet . Cli . Utils ;
97
108namespace Microsoft . DotNet . Cli ;
@@ -21,27 +19,21 @@ internal static class CommonOptionsFactory
2119 {
2220 Description = CliStrings . SDKDiagnosticsCommandDefinition ,
2321 Recursive = recursive ,
24- Arity = ArgumentArity . Zero
22+ Arity = ArgumentArity . Zero ,
23+ Action = new SetDiagnosticModeAction ( )
2524 } ;
2625
27- internal class SetDiagnosticModeAction ( Option < bool > diagnosticOption ) : SynchronousCommandLineAction
26+ /// <summary>
27+ /// Sets a few verbose diagnostics flags across the CLI.
28+ /// Other commands may also use this to set their verbosity flags to a higher value or similar behaviors.
29+ /// </summary>
30+ internal class SetDiagnosticModeAction ( ) : SynchronousCommandLineAction
2831 {
2932 public override int Invoke ( ParseResult parseResult )
3033 {
31- if ( parseResult . IsDotnetBuiltInCommand ( ) )
32- {
33- var diagIsChildOfRoot = parseResult . RootCommandResult . Children . FirstOrDefault ( ( s ) => s is OptionResult opt && opt . Option == diagnosticOption ) is not null ;
34-
35- // We found --diagnostic or -d, but we still need to determine whether the option should
36- // be attached to the dotnet command or the subcommand.
37- if ( diagIsChildOfRoot )
38- {
39- Environment . SetEnvironmentVariable ( CommandLoggingContext . Variables . Verbose , bool . TrueString ) ;
40- CommandLoggingContext . SetVerbose ( true ) ;
41- Reporter . Reset ( ) ;
42- }
43- }
44-
34+ Environment . SetEnvironmentVariable ( CommandLoggingContext . Variables . Verbose , bool . TrueString ) ;
35+ CommandLoggingContext . SetVerbose ( true ) ;
36+ Reporter . Reset ( ) ;
4537 return 0 ;
4638 }
4739 }
0 commit comments