Skip to content

Commit e026384

Browse files
committed
WIP: rip and tear
1 parent 73d5633 commit e026384

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
@@ -86,9 +86,12 @@ static bool ErrorContainsAllParts(ReadOnlySpan<char> error, string[] parts)
8686

8787
public static string RootSubCommandResult(this ParseResult parseResult)
8888
{
89-
return parseResult.RootCommandResult.Children?
90-
.Select(child => GetSymbolResultValue(parseResult, child))
91-
.FirstOrDefault(subcommand => !string.IsNullOrEmpty(subcommand)) ?? string.Empty;
89+
CommandResult commandResult = parseResult.CommandResult;
90+
while (commandResult != parseResult.RootCommandResult && commandResult.Parent is CommandResult parentCommand)
91+
{
92+
commandResult = parentCommand;
93+
}
94+
return commandResult.Command.Name;
9295
}
9396

9497
public static bool IsDotnetBuiltInCommand(this ParseResult parseResult)
@@ -102,12 +105,7 @@ public static bool IsTopLevelDotnetCommand(this ParseResult parseResult)
102105
return parseResult.CommandResult.Command.Equals(Parser.RootCommand) && string.IsNullOrEmpty(parseResult.RootSubCommandResult());
103106
}
104107

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

112110
public static int HandleMissingCommand(this ParseResult parseResult)
113111
{

src/Cli/dotnet/Parser.cs

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

100100
public static readonly Option<bool> VersionOption = new("--version")
101101
{
102-
Arity = ArgumentArity.Zero
102+
Arity = ArgumentArity.Zero,
103+
Action = new PrintVersionAction()
103104
};
104105

106+
internal class PrintVersionAction : System.CommandLine.Invocation.SynchronousCommandLineAction
107+
{
108+
public PrintVersionAction()
109+
{
110+
Terminating = true;
111+
}
112+
public override int Invoke(ParseResult parseResult)
113+
{
114+
CommandLineInfo.PrintVersion();
115+
return 0;
116+
}
117+
}
118+
105119
public static readonly Option<bool> InfoOption = new("--info")
106120
{
107-
Arity = ArgumentArity.Zero
121+
Arity = ArgumentArity.Zero,
122+
Action = new PrintInfoAction()
108123
};
109124

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

0 commit comments

Comments
 (0)