Skip to content

Commit

Permalink
Reuse existing models and ensure help command handler emition doesn't…
Browse files Browse the repository at this point in the history
… run too frequently by using a custom equality comparer for help-related scenarios
  • Loading branch information
DoctorKrolic committed Jun 5, 2024
1 parent 510ee8d commit 6e698ac
Show file tree
Hide file tree
Showing 11 changed files with 149 additions and 105 deletions.
22 changes: 11 additions & 11 deletions src/ArgumentParsing.Generators/ArgumentParserGenerator.CodeGen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -876,10 +876,10 @@ private static void EmitArgumentParser(SourceProductionContext context, (Argumen
context.AddSource($"{qualifiedName}.g.cs", writer.ToString().Trim());
}

private static void EmitHelpCommandHandler(SourceProductionContext context, (OptionsHelpInfo, AssemblyVersionInfo) infos)
private static void EmitHelpCommandHandler(SourceProductionContext context, (OptionsInfo, AssemblyVersionInfo) infos)
{
var (optionsHelpInfo, assemblyVersionInfo) = infos;
var (qualifiedName, optionHelpInfos, parameterHelpInfos, remainingParametersHelpInfo, helpTextGeneratorInfo) = optionsHelpInfo;
var (optionsInfo, assemblyVersionInfo) = infos;
var (qualifiedName, _, optionInfos, parameterInfos, remainingParametersInfo, helpTextGeneratorInfo) = optionsInfo;

var writer = new CodeWriter();

Expand Down Expand Up @@ -923,10 +923,10 @@ private static void EmitHelpCommandHandler(SourceProductionContext context, (Opt
writer.CloseBlock();
writer.WriteLine("helpBuilder.AppendLine();");
writer.CloseBlock();
if (optionHelpInfos.Any())
if (optionInfos.Any())
{
writer.WriteLine("helpBuilder.AppendLine(\"OPTIONS:\");");
foreach (var info in optionHelpInfos)
foreach (var info in optionInfos)
{
writer.WriteLine("helpBuilder.AppendLine();");
writer.Write("helpBuilder.AppendLine(\" ");
Expand Down Expand Up @@ -964,13 +964,13 @@ private static void EmitHelpCommandHandler(SourceProductionContext context, (Opt
writer.WriteLine("\");");
}
}
if (parameterHelpInfos.Any())
if (parameterInfos.Any())
{
writer.WriteLine("helpBuilder.AppendLine();");
writer.WriteLine("helpBuilder.AppendLine(\"PARAMETERS:\");");
for (var i = 0; i < parameterHelpInfos.Length; i++)
for (var i = 0; i < parameterInfos.Length; i++)
{
var info = parameterHelpInfos[i];
var info = parameterInfos[i];

writer.WriteLine("helpBuilder.AppendLine();");
writer.Write($"helpBuilder.AppendLine(\" {info.Name} (at index {i})");
Expand All @@ -996,13 +996,13 @@ private static void EmitHelpCommandHandler(SourceProductionContext context, (Opt
writer.WriteLine("\");");
}
}
if (remainingParametersHelpInfo is not null)
if (remainingParametersInfo is not null)
{
writer.WriteLine("helpBuilder.AppendLine();");
writer.Write("helpBuilder.AppendLine(\" Remaining parameters");
if (remainingParametersHelpInfo.HelpDescription is not null)
if (remainingParametersInfo.HelpDescription is not null)
{
writer.Write($"\\t{remainingParametersHelpInfo.HelpDescription}");
writer.Write($"\\t{remainingParametersInfo.HelpDescription}");
}
writer.WriteLine("\");");
}
Expand Down
Loading

0 comments on commit 6e698ac

Please sign in to comment.