Skip to content

Commit 35778b0

Browse files
committed
WIP: rip and tear
1 parent c173b9e commit 35778b0

File tree

10 files changed

+160
-178
lines changed

10 files changed

+160
-178
lines changed

src/Cli/dotnet/Commands/Hidden/InternalReportInstallSuccess/InternalReportInstallSuccessCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ internal ThreadBlockingTelemetry()
4949
{
5050
var sessionId =
5151
Environment.GetEnvironmentVariable(TelemetrySessionIdEnvironmentVariableName);
52-
telemetry = new Telemetry.Telemetry(new NoOpFirstTimeUseNoticeSentinel(), sessionId, blockThreadInitialization: true);
52+
telemetry = new Telemetry.Telemetry(sessionId, blockThreadInitialization: true);
5353
}
5454
public bool Enabled => telemetry.Enabled;
5555

src/Cli/dotnet/Commands/MSBuild/MSBuildLogger.cs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ namespace Microsoft.DotNet.Cli.Commands.MSBuild;
1313

1414
public sealed class MSBuildLogger : INodeLogger
1515
{
16-
private readonly IFirstTimeUseNoticeSentinel _sentinel =
17-
new FirstTimeUseNoticeSentinel();
1816
private readonly ITelemetry _telemetry;
1917

2018
internal const string TargetFrameworkTelemetryEventName = "targetframeworkeval";
@@ -64,7 +62,6 @@ public MSBuildLogger()
6462
// time they will read from the same global queue and cause
6563
// sending duplicated events. Disable sender to reduce it.
6664
_telemetry = new Telemetry.Telemetry(
67-
_sentinel,
6865
sessionId,
6966
senderCount: 0);
7067
}
@@ -215,14 +212,6 @@ private void OnTelemetryLogged(object sender, TelemetryEventArgs args)
215212

216213
public void Shutdown()
217214
{
218-
try
219-
{
220-
_sentinel?.Dispose();
221-
}
222-
catch (Exception)
223-
{
224-
// Exceptions during telemetry shouldn't cause anything else to fail
225-
}
226215
}
227216

228217
public LoggerVerbosity Verbosity { get; set; }

src/Cli/dotnet/CommonOptionsFactory.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
#nullable disable
55

66
using System.CommandLine;
7+
using System.CommandLine.Parsing;
8+
using Microsoft.DotNet.Cli.Extensions;
9+
using Microsoft.DotNet.Cli.Utils;
710

811
namespace Microsoft.DotNet.Cli;
912

@@ -21,4 +24,25 @@ internal static class CommonOptionsFactory
2124
Recursive = recursive,
2225
Arity = ArgumentArity.Zero
2326
};
27+
28+
internal class SetDiagnosticModeAction(Option<bool> diagnosticOption) : System.CommandLine.Invocation.SynchronousCommandLineAction
29+
{
30+
public override int Invoke(ParseResult parseResult)
31+
{
32+
if (parseResult.IsDotnetBuiltInCommand())
33+
{
34+
var diagIsChildOfRoot = parseResult.RootCommandResult.Children.FirstOrDefault((s) => s is OptionResult opt && opt.Option == diagnosticOption) is not null;
35+
36+
// We found --diagnostic or -d, but we still need to determine whether the option should
37+
// be attached to the dotnet command or the subcommand.
38+
if (diagIsChildOfRoot)
39+
{
40+
Environment.SetEnvironmentVariable(CommandLoggingContext.Variables.Verbose, bool.TrueString);
41+
CommandLoggingContext.SetVerbose(true);
42+
Reporter.Reset();
43+
}
44+
}
45+
return 0;
46+
}
47+
}
2448
}

src/Cli/dotnet/Extensions/ParseResultExtensions.cs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,12 @@ static bool ErrorContainsAllParts(ReadOnlySpan<char> error, string[] parts)
8484

8585
public static string RootSubCommandResult(this ParseResult parseResult)
8686
{
87-
return parseResult.RootCommandResult.Children?
88-
.Select(child => GetSymbolResultValue(parseResult, child))
89-
.FirstOrDefault(subcommand => !string.IsNullOrEmpty(subcommand)) ?? string.Empty;
87+
CommandResult commandResult = parseResult.CommandResult;
88+
while (commandResult != parseResult.RootCommandResult && commandResult.Parent is CommandResult parentCommand)
89+
{
90+
commandResult = parentCommand;
91+
}
92+
return commandResult.Command.Name;
9093
}
9194

9295
public static bool IsDotnetBuiltInCommand(this ParseResult parseResult)
@@ -100,12 +103,7 @@ public static bool IsTopLevelDotnetCommand(this ParseResult parseResult)
100103
return parseResult.CommandResult.Command.Equals(Parser.RootCommand) && string.IsNullOrEmpty(parseResult.RootSubCommandResult());
101104
}
102105

103-
public static bool CanBeInvoked(this ParseResult parseResult)
104-
{
105-
return GetBuiltInCommand(parseResult.RootSubCommandResult()) != null ||
106-
parseResult.Tokens.Any(token => token.Type == TokenType.Directive) ||
107-
(parseResult.IsTopLevelDotnetCommand() && string.IsNullOrEmpty(parseResult.GetValue(DotnetSubCommand)));
108-
}
106+
public static bool CanBeInvoked(this ParseResult parseResult) => parseResult.Action is not null;
109107

110108
public static int HandleMissingCommand(this ParseResult parseResult)
111109
{

src/Cli/dotnet/Parser.cs

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,14 +101,43 @@ public static class Parser
101101

102102
public static readonly Option<bool> VersionOption = new("--version")
103103
{
104-
Arity = ArgumentArity.Zero
104+
Arity = ArgumentArity.Zero,
105+
Action = new PrintVersionAction()
105106
};
106107

108+
internal class PrintVersionAction : System.CommandLine.Invocation.SynchronousCommandLineAction
109+
{
110+
public PrintVersionAction()
111+
{
112+
Terminating = true;
113+
}
114+
public override int Invoke(ParseResult parseResult)
115+
{
116+
CommandLineInfo.PrintVersion();
117+
return 0;
118+
}
119+
}
120+
107121
public static readonly Option<bool> InfoOption = new("--info")
108122
{
109-
Arity = ArgumentArity.Zero
123+
Arity = ArgumentArity.Zero,
124+
Action = new PrintInfoAction()
110125
};
111126

127+
internal class PrintInfoAction : System.CommandLine.Invocation.SynchronousCommandLineAction
128+
{
129+
public PrintInfoAction()
130+
{
131+
Terminating = true;
132+
}
133+
134+
public override int Invoke(ParseResult parseResult)
135+
{
136+
CommandLineInfo.PrintInfo();
137+
return 0;
138+
}
139+
}
140+
112141
public static readonly Option<bool> ListSdksOption = new("--list-sdks")
113142
{
114143
Arity = ArgumentArity.Zero

0 commit comments

Comments
 (0)