Skip to content

Commit

Permalink
fix always lower bug
Browse files Browse the repository at this point in the history
  • Loading branch information
DearVa committed Dec 10, 2023
1 parent 1e90a34 commit 6bc8a27
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/.idea/.idea.AntelCat.Parameterization/.idea/.name

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/Antelcat.Parameterization.Demo/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace Antelcat.Parameterization.Demo;

[Parameterization]
[Parameterization(CaseSensitive = true)]
public static partial class Program
{
public static async Task Main(string[] args)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<Nullable>enable</Nullable>
<EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules>
<Company>Antelcat</Company>
<AssemblyVersion>1.2.1</AssemblyVersion>
<FileVersion>1.2.1</FileVersion>
<AssemblyVersion>1.2.2</AssemblyVersion>
<FileVersion>1.2.2</FileVersion>
<AnalysisMode>Recommended</AnalysisMode>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ public static void ParseArguments(
IReadOnlyList<string> arguments,
IReadOnlyList<(string fullName, string? shortName)> parameterNames,
IReadOnlyList<string?> defaultValues,
IReadOnlyList<{{Global.TypeConverter}}> argumentConverters)
IReadOnlyList<{{Global.TypeConverter}}> argumentConverters,
bool ignoreCase)
{
var isNamedArgumentUsed = false;
for (var i = 1; i < arguments.Count; i++)
Expand All @@ -96,21 +97,19 @@ public static void ParseArguments(
}
if (argument.StartsWith("--"))
{
argument = argument[2..];
argumentIndex = parameterNames.FindIndexOf(x => x.fullName == argument);
argumentIndex = parameterNames.FindIndexOf(x => argument[2..].Equals(x.fullName, ignoreCase ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal));
if (argumentIndex == -1)
{
throw new ArgumentException($"Argument \"--{argument}\" not found.");
throw new ArgumentException($"Argument \"{argument}\" not found.");
}
isNamedArgumentUsed = true;
}
else if (argument.StartsWith('-'))
{
argument = argument[1..];
argumentIndex = parameterNames.FindIndexOf(x => x.shortName == argument);
argumentIndex = parameterNames.FindIndexOf(x => argument[1..].Equals(x.shortName, ignoreCase ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal));
if (argumentIndex == -1)
{
throw new ArgumentException($"Argument \"-{argument}\" not found.");
throw new ArgumentException($"Argument \"{argument}\" not found.");
}
isNamedArgumentUsed = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ symbol is not IMethodSymbol
: convertersGenerator.ConvertersMap[syntaxContext.SemanticModel.GetSymbolInfo(x.Item2.Type.NotNull()).Symbol.NotNull<ITypeSymbol>()])
.Select(name => $"{Global.GlobalNamespace}.Converters.{name}Converter"))} }};")
.AppendLine(
$"{Global.GlobalNamespace}.Common.ParseArguments(parsedArguments, arguments, argumentNames, defaultValues, argumentConverters);");
$"{Global.GlobalNamespace}.Common.ParseArguments(parsedArguments, arguments, argumentNames, defaultValues, argumentConverters, {(caseSensitive ? "false" : "true")});");

if (method.ReturnType.IsAwaitable(syntaxContext.SemanticModel))
{
Expand Down Expand Up @@ -288,21 +288,22 @@ symbol is not IMethodSymbol
foreach ({{Global.Match}} match in {{Global.GlobalNamespace}}.Common.CommandRegex.Matches(input))
{
var part = match.Value;
part = {{Global.GlobalNamespace}}.Common.QuotationRegex.Replace(part, "").Replace("\\\"", "\""){{(caseSensitive ? "" : ".ToLower()")}};
part = {{Global.GlobalNamespace}}.Common.QuotationRegex.Replace(part, "").Replace("\\\"", "\"");
arguments.Add(part);
}
{{"return ".If(isAsync)}}ExecuteArguments{{"Async".If(isAsync)}}(arguments);
}
[global::System.Diagnostics.CodeAnalysis.SuppressMessage("RuleCategory", "CS8625:Cannot convert null literal to non-nullable reference type", Justification = "Generated Code")]
private {{"static ".If(isStatic)}}{{(isAsync ? $"async {Global.ValueTask}" : "void")}} ExecuteArguments{{"Async".If(isAsync)}}({{Global.GenericIReadonlyList}}<{{Global.String}}> arguments)
{
if (arguments.Count == 0)
{
return;
}
switch (arguments[0])
switch (arguments[0]{{".ToLower()".If(!caseSensitive)}})
{
{{caseBuilder}}
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
<TargetFramework>netstandard2.0</TargetFramework>
<LangVersion>preview</LangVersion>
<Nullable>enable</Nullable>
<Version>1.2.1</Version>
<Version>1.2.2</Version>
<Company>Antelcat</Company>
<AssemblyVersion>1.2.1</AssemblyVersion>
<FileVersion>1.2.1</FileVersion>
<AssemblyVersion>1.2.2</AssemblyVersion>
<FileVersion>1.2.2</FileVersion>
<Title>Effortless Command-Line Application Builder</Title>
<Description>A powerful source generator designed to revolutionize the way you create command-line applications. This tool simplifies the process of building CLI applications by automatically generating parsing methods with just attribute marking on classes and methods.</Description>
<PackageProjectUrl>https://github.com/Antelcat/Antelcat.Parameterization</PackageProjectUrl>
Expand Down

0 comments on commit 6bc8a27

Please sign in to comment.