Skip to content

Commit

Permalink
Remove [GenerateDefaultVersionSpecialCommand] attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
DoctorKrolic committed Jul 5, 2024
1 parent c4a4347 commit 82246de
Show file tree
Hide file tree
Showing 6 changed files with 4 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public partial class ArgumentParserGenerator
private static void EmitArgumentParser(SourceProductionContext context, (ArgumentParserInfo, EnvironmentInfo) infos)
{
var (parserInfo, environmentInfo) = infos;
var (canUseOptimalSpanBasedAlgorithm, hasStringStartsWithCharOverload, _) = environmentInfo;
var (canUseOptimalSpanBasedAlgorithm, hasStringStartsWithCharOverload) = environmentInfo;

var cancellationToken = context.CancellationToken;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -528,10 +528,7 @@ private static (EnvironmentInfo EnvironmentInfo, AssemblyVersionInfo AssemblyVer

cancellationToken.ThrowIfCancellationRequested();

var generateDefaultVersionSpecialCommandAttributeType = compilation.GetTypeByMetadataName("ArgumentParsing.SpecialCommands.Version.GenerateDefaultVersionSpecialCommandAttribute");
var forceDefaultVersionCommand = compilation.Assembly.GetAttributes().Any(a => SymbolEqualityComparer.Default.Equals(a.AttributeClass, generateDefaultVersionSpecialCommandAttributeType));

var environmentInfo = new EnvironmentInfo(canUseOptimalSpanBasedAlgorithm, hasStringStartsWithCharOverload, forceDefaultVersionCommand);
var environmentInfo = new EnvironmentInfo(canUseOptimalSpanBasedAlgorithm, hasStringStartsWithCharOverload);

var assembly = compilation.Assembly;
var assemblyVersionInfo = new AssemblyVersionInfo(
Expand Down
7 changes: 1 addition & 6 deletions src/ArgumentParsing.Generators/ArgumentParserGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,6 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
.Collect()
.Select((parsers, _) => !parsers.IsEmpty);

var shouldGenerateDefaultVersionCommand = environmentInfo
.Select((info, _) => info.ForceDefaultVersionCommand)
.Combine(hasAnyParsersWithDefaultHandlers)
.Select((pair, _) => pair.Left || pair.Right);

context.RegisterSourceOutput(assemblyVersionInfo.Combine(shouldGenerateDefaultVersionCommand), EmitVersionCommandHandler);
context.RegisterSourceOutput(assemblyVersionInfo.Combine(hasAnyParsersWithDefaultHandlers), EmitVersionCommandHandler);
}
}
3 changes: 1 addition & 2 deletions src/ArgumentParsing.Generators/Models/EnvironmentInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@ namespace ArgumentParsing.Generators.Models;

internal sealed record EnvironmentInfo(
bool CanUseOptimalSpanBasedAlgorithm,
bool HasStringStartsWithCharOverload,
bool ForceDefaultVersionCommand);
bool HasStringStartsWithCharOverload);

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -346,18 +346,6 @@ class InfoCommandHandler : ISpecialCommandHandler
await VerifyGeneratorAsync(source);
}

[Fact]
public async Task SpecialCommandHandlers_ForceDefaultVersionCommand()
{
var source = """
using ArgumentParsing.SpecialCommands.Version;
[assembly: GenerateDefaultVersionSpecialCommand]
""";

await VerifyGeneratorAsync(source, ("VersionCommandHandler.TestProject.g.cs", VersionCommandHander));
}

[Fact]
public async Task SpecialCommandHandlers_HelpTextGenerator_InvalidTypeSpecifier_Null()
{
Expand Down

0 comments on commit 82246de

Please sign in to comment.