Skip to content

Commit

Permalink
Merge pull request #1872 from adamsitnik/sclUpdate
Browse files Browse the repository at this point in the history
System.CommandLine update
  • Loading branch information
JoeRobich committed Jun 15, 2023
2 parents 1297f6f + fd94d18 commit 3491d2c
Show file tree
Hide file tree
Showing 10 changed files with 167 additions and 239 deletions.
12 changes: 6 additions & 6 deletions eng/Version.Details.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,18 @@
<Uri>https://github.com/dotnet/symreader</Uri>
<Sha>27e584661980ee6d82c419a2a471ae505b7d122e</Sha>
</Dependency>
<Dependency Name="Microsoft.SourceBuild.Intermediate.command-line-api" Version="0.1.356401">
<Dependency Name="Microsoft.SourceBuild.Intermediate.command-line-api" Version="0.1.430701">
<Uri>https://github.com/dotnet/command-line-api</Uri>
<Sha>8374d5fca634a93458c84414b1604c12f765d1ab</Sha>
<Sha>02fe27cd6a9b001c8feb7938e6ef4b3799745759</Sha>
<SourceBuild RepoName="command-line-api" ManagedOnly="true" />
</Dependency>
<Dependency Name="System.CommandLine" Version="2.0.0-beta4.22564.1">
<Dependency Name="System.CommandLine" Version="2.0.0-beta4.23307.1">
<Uri>https://github.com/dotnet/command-line-api</Uri>
<Sha>8374d5fca634a93458c84414b1604c12f765d1ab</Sha>
<Sha>02fe27cd6a9b001c8feb7938e6ef4b3799745759</Sha>
</Dependency>
<Dependency Name="System.CommandLine.Rendering" Version="0.4.0-alpha.22564.1">
<Dependency Name="System.CommandLine.Rendering" Version="0.4.0-alpha.23307.1">
<Uri>https://github.com/dotnet/command-line-api</Uri>
<Sha>8374d5fca634a93458c84414b1604c12f765d1ab</Sha>
<Sha>02fe27cd6a9b001c8feb7938e6ef4b3799745759</Sha>
</Dependency>
</ProductDependencies>
<ToolsetDependencies>
Expand Down
4 changes: 2 additions & 2 deletions eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
</PropertyGroup>
<PropertyGroup>
<!-- command-line-api -->
<SystemCommandLineVersion>2.0.0-beta4.22564.1</SystemCommandLineVersion>
<SystemCommandLineRenderingVersion>0.4.0-alpha.22564.1</SystemCommandLineRenderingVersion>
<SystemCommandLineVersion>2.0.0-beta4.23307.1</SystemCommandLineVersion>
<SystemCommandLineRenderingVersion>0.4.0-alpha.23307.1</SystemCommandLineRenderingVersion>
<!-- corefx -->
<MicrosoftVisualBasicVersion>10.3.0</MicrosoftVisualBasicVersion>
<!-- msbuild -->
Expand Down
102 changes: 0 additions & 102 deletions src/CommandLineExtensions.cs

This file was deleted.

27 changes: 13 additions & 14 deletions src/Commands/FormatAnalyzersCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

using System.Collections.Immutable;
using System.CommandLine;
using System.CommandLine.Invocation;
using System.CommandLine.Parsing;
using System.CommandLine.IO;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using static Microsoft.CodeAnalysis.Tools.FormatCommandCommon;
Expand All @@ -14,52 +14,51 @@ internal static class FormatAnalyzersCommand
{
private static readonly FormatAnalyzersHandler s_analyzerHandler = new();

internal static Command GetCommand()
internal static CliCommand GetCommand()
{
var command = new Command("analyzers", Resources.Run_3rd_party_analyzers__and_apply_fixes)
var command = new CliCommand("analyzers", Resources.Run_3rd_party_analyzers__and_apply_fixes)
{
DiagnosticsOption,
ExcludeDiagnosticsOption,
SeverityOption,
};
command.AddCommonOptions();
command.Handler = s_analyzerHandler;
command.Action = s_analyzerHandler;
return command;
}

private class FormatAnalyzersHandler : ICommandHandler
private class FormatAnalyzersHandler : CliAction
{
public int Invoke(InvocationContext context) => InvokeAsync(context).GetAwaiter().GetResult();
public override int Invoke(ParseResult parseResult) => InvokeAsync(parseResult, CancellationToken.None).GetAwaiter().GetResult();

public async Task<int> InvokeAsync(InvocationContext context)
public override async Task<int> InvokeAsync(ParseResult parseResult, CancellationToken cancellationToken)
{
var parseResult = context.ParseResult;
var formatOptions = parseResult.ParseVerbosityOption(FormatOptions.Instance);
var logger = context.Console.SetupLogging(minimalLogLevel: formatOptions.LogLevel, minimalErrorLevel: LogLevel.Warning);
var logger = new SystemConsole().SetupLogging(minimalLogLevel: formatOptions.LogLevel, minimalErrorLevel: LogLevel.Warning);
formatOptions = parseResult.ParseCommonOptions(formatOptions, logger);
formatOptions = parseResult.ParseWorkspaceOptions(formatOptions);

if (parseResult.HasOption(SeverityOption) &&
if (parseResult.GetResult(SeverityOption) is not null &&
parseResult.GetValue(SeverityOption) is string { Length: > 0 } analyzerSeverity)
{
formatOptions = formatOptions with { AnalyzerSeverity = GetSeverity(analyzerSeverity) };
}

if (parseResult.HasOption(DiagnosticsOption) &&
if (parseResult.GetResult(DiagnosticsOption) is not null &&
parseResult.GetValue(DiagnosticsOption) is string[] { Length: > 0 } diagnostics)
{
formatOptions = formatOptions with { Diagnostics = diagnostics.ToImmutableHashSet() };
}

if (parseResult.HasOption(ExcludeDiagnosticsOption) &&
if (parseResult.GetResult(ExcludeDiagnosticsOption) is not null &&
parseResult.GetValue(ExcludeDiagnosticsOption) is string[] { Length: > 0 } excludeDiagnostics)
{
formatOptions = formatOptions with { ExcludeDiagnostics = excludeDiagnostics.ToImmutableHashSet() };
}

formatOptions = formatOptions with { FixCategory = FixCategory.Analyzers };

return await FormatAsync(formatOptions, logger, context.GetCancellationToken()).ConfigureAwait(false);
return await FormatAsync(formatOptions, logger, cancellationToken).ConfigureAwait(false);
}
}
}
Expand Down
Loading

0 comments on commit 3491d2c

Please sign in to comment.