Skip to content

Commit 91f0f76

Browse files
committed
Fix: Various cleanups
1 parent 2e634a8 commit 91f0f76

File tree

26 files changed

+111
-115
lines changed

26 files changed

+111
-115
lines changed

src/CodeOfChaos.CliArgsParser.Generators.Sample/Example.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,13 @@ public async Task ExecuteAsync(CommandParameters parameters) {
3737
foreach (string value in parameters.OptionalTestOtherElseValue) {
3838
Console.WriteLine($" - {value}");
3939
}
40-
} else {
40+
}
41+
else {
4142
Console.WriteLine("OptionalTestOtherElseValue is empty.");
4243
}
4344

4445
// Simulate some asynchronous work
45-
await Task.Delay(100); // Example of an asynchronous operation
46+
await Task.Delay(100);// Example of an asynchronous operation
4647

4748
Console.WriteLine("Command executed successfully.");
4849
}

src/CodeOfChaos.CliArgsParser.Generators/CodeOfChaos.CliArgsParser.Generators.csproj

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,21 @@
2626
</PropertyGroup>
2727

2828
<ItemGroup>
29-
<None Include="..\..\LICENSE" Pack="true" PackagePath="" />
30-
<None Include="..\..\README.md" Pack="true" PackagePath="" />
29+
<None Include="..\..\LICENSE" Pack="true" PackagePath=""/>
30+
<None Include="..\..\README.md" Pack="true" PackagePath=""/>
3131
</ItemGroup>
3232

3333
<ItemGroup>
3434
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.11.0">
3535
<PrivateAssets>all</PrivateAssets>
3636
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
3737
</PackageReference>
38-
<PackageReference Include="Microsoft.CodeAnalysis.Common" Version="4.12.0" />
39-
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.12.0" />
38+
<PackageReference Include="Microsoft.CodeAnalysis.Common" Version="4.12.0"/>
39+
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.12.0"/>
4040
</ItemGroup>
4141

4242
<ItemGroup>
43-
<None Include="$(OutputPath)\$(AssemblyName).dll" Pack="true" PackagePath="analyzers/dotnet/cs" Visible="false" />
43+
<None Include="$(OutputPath)\$(AssemblyName).dll" Pack="true" PackagePath="analyzers/dotnet/cs" Visible="false"/>
4444
</ItemGroup>
4545

4646

src/CodeOfChaos.CliArgsParser.Generators/Content/CommandGenerator/ClassDto.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public class ClassDto(ISymbol symbol, ClassDeclarationSyntax syntax) {
2727

2828
private string CommandName =>
2929
_commandNameAttribute?.ConstructorArguments.ElementAtOrDefault(0).Value?.ToString()
30-
?? ClassName.Replace("Command", "").ToLowerInvariant(); // Maybe create a ToKebabCase method?
30+
?? ClassName.Replace("Command", "").ToLowerInvariant();// Maybe create a ToKebabCase method?
3131

3232
private string Description => _descriptionAttribute?.ConstructorArguments.ElementAtOrDefault(0).Value?.ToString() ?? string.Empty;
3333

@@ -61,7 +61,7 @@ public void ToCommandInitialization(GeneratorStringBuilder builder) {
6161
builder.AppendLine("public Task InitializeAsync(IUserInputRegistry registry) {")
6262
.Indent()
6363
.AppendLine($"var data = {GenericTypeDisplayName}.FromRegistry(registry);")
64-
.AppendLine($"return ExecuteAsync(data);")
64+
.AppendLine("return ExecuteAsync(data);")
6565
.UnIndent()
6666
.AppendLine("}");
6767
}

src/CodeOfChaos.CliArgsParser.Generators/Content/ParametersGenerator/Generator.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ private static void GenerateSources(SourceProductionContext context, (Compilatio
7878
.AppendLine("public T NewFromRegistry<T>(IUserInputRegistry registry) where T : struct, IParameters {")
7979
.Indent()
8080
.AppendLine($"if(typeof(T) != typeof({dto.ClassName})) throw new ArgumentException(); ")
81-
.AppendLine( "object boxed = FromRegistry(registry)!;")
82-
.AppendLine( "return (T)boxed;")
81+
.AppendLine("object boxed = FromRegistry(registry)!;")
82+
.AppendLine("return (T)boxed;")
8383
.UnIndentLine("}");
8484

8585
builder

src/CodeOfChaos.CliArgsParser.Generators/Content/ParametersGenerator/PropertyDto.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,16 @@ public class PropertyDto(IPropertySymbol symbol, PropertyDeclarationSyntax synta
1717
private readonly Location _location = symbol.Locations.First();
1818

1919
public readonly bool IsFlag = parameterAttribute.ConstructorArguments.ElementAtOrDefault(2).Value as uint? == 1u;
20+
public readonly bool IsNullableAnnotated = symbol.Type.NullableAnnotation == NullableAnnotation.Annotated;
21+
public readonly bool IsPropertyValueType = symbol.Type.IsValueType;
2022
public readonly bool IsRequiredProperty = syntax.Modifiers.Any(SyntaxKind.RequiredKeyword);
21-
23+
2224
public readonly string ParameterName = parameterAttribute.ConstructorArguments.ElementAt(0).Value?.ToString() ?? string.Empty;
2325
public readonly string? ParameterShortName = parameterAttribute.ConstructorArguments.ElementAtOrDefault(1).Value?.ToString();
2426

2527
public readonly string PropertyDefaultValue = ToPropertyDefaultValue(syntax, symbol);
2628
public readonly string PropertyName = syntax.Identifier.ToString();
2729
public readonly TypeSyntax PropertyType = syntax.Type;
28-
public readonly bool IsPropertyValueType = symbol.Type.IsValueType;
29-
public readonly bool IsNullableAnnotated = symbol.Type.NullableAnnotation == NullableAnnotation.Annotated;
3030
public string Description => _descriptionAttribute?.ConstructorArguments.ElementAtOrDefault(0).Value?.ToString() ?? string.Empty;
3131

3232
// diagnostics
@@ -65,15 +65,15 @@ private static string ToPropertyDefaultValue(PropertyDeclarationSyntax propertyS
6565
// -----------------------------------------------------------------------------------------------------------------
6666
public string ToPropertyInitialization() {
6767
return this switch {
68-
{ IsRequiredProperty: true }
68+
{ IsRequiredProperty: true }
6969
=> $"{PropertyName} = registry.GetParameterByPossibleNames<{PropertyType}>(\"--{ParameterName}\", \"-{ParameterShortName}\"),",
7070
{ IsPropertyValueType: true, IsNullableAnnotated: false }
7171
=> $"{PropertyName} = registry.GetOptionalParameterByPossibleNames<{PropertyType}?>(\"--{ParameterName}\", \"-{ParameterShortName}\") ?? {PropertyDefaultValue},",
72-
_
72+
_
7373
=> $"{PropertyName} = registry.GetOptionalParameterByPossibleNames<{PropertyType}>(\"--{ParameterName}\", \"-{ParameterShortName}\") ?? {PropertyDefaultValue},"
7474
};
7575
}
76-
76+
7777

7878
public void ReportDiagnostics(SourceProductionContext context) {
7979
if (IsDuplicateName) context.ReportParameterPropertyDuplicateNames(_location, PropertyName, ParameterName);

src/CodeOfChaos.CliArgsParser.Generators/Helpers/GeneratorStringBuilder.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public GeneratorStringBuilder AppendUsings(params string[] usings) {
2020
foreach (string @using in usings) {
2121
AppendLine($"using {@using};");
2222
}
23+
2324
return this;
2425
}
2526

src/CodeOfChaos.CliArgsParser.Library/CodeOfChaos.CliArgsParser.Library.csproj

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,19 @@
2323
</PropertyGroup>
2424

2525
<ItemGroup>
26-
<None Include="..\..\LICENSE" Pack="true" PackagePath="" />
27-
<None Include="..\..\README.md" Pack="true" PackagePath="" />
28-
<None Include="..\..\assets/icon.png" Pack="true" PackagePath="" />
26+
<None Include="..\..\LICENSE" Pack="true" PackagePath=""/>
27+
<None Include="..\..\README.md" Pack="true" PackagePath=""/>
28+
<None Include="..\..\assets/icon.png" Pack="true" PackagePath=""/>
2929
</ItemGroup>
30-
30+
3131
<ItemGroup>
32-
<ProjectReference Include="..\CodeOfChaos.CliArgsParser.Generators\CodeOfChaos.CliArgsParser.Generators.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
33-
<ProjectReference Include="..\CodeOfChaos.CliArgsParser\CodeOfChaos.CliArgsParser.csproj" />
32+
<ProjectReference Include="..\CodeOfChaos.CliArgsParser.Generators\CodeOfChaos.CliArgsParser.Generators.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false"/>
33+
<ProjectReference Include="..\CodeOfChaos.CliArgsParser\CodeOfChaos.CliArgsParser.csproj"/>
3434
</ItemGroup>
3535

3636
<ItemGroup>
37-
<PackageReference Include="AterraEngine.Unions" Version="2.5.0" />
38-
<PackageReference Include="CodeOfChaos.Ansi" Version="0.1.7" />
37+
<PackageReference Include="AterraEngine.Unions" Version="2.5.0"/>
38+
<PackageReference Include="CodeOfChaos.Ansi" Version="0.1.7"/>
3939
</ItemGroup>
4040

4141
</Project>

src/CodeOfChaos.CliArgsParser.Library/CommandAtlases/DownloadIcon/DownloadIconCommand.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
using CodeOfChaos.CliArgsParser.Contracts;
66

77
namespace CodeOfChaos.CliArgsParser.Library.CommandAtlases.DownloadIcon;
8-
98
// ---------------------------------------------------------------------------------------------------------------------
109
// Code
1110
// ---------------------------------------------------------------------------------------------------------------------
@@ -16,7 +15,5 @@ public partial class DownloadIconCommand : ICommand<DownloadIconParameters> {
1615
// -----------------------------------------------------------------------------------------------------------------
1716
// Methods
1817
// -----------------------------------------------------------------------------------------------------------------
19-
public Task ExecuteAsync(DownloadIconParameters parameters) {
20-
throw new NotImplementedException();
21-
}
18+
public Task ExecuteAsync(DownloadIconParameters parameters) => throw new NotImplementedException();
2219
}

src/CodeOfChaos.CliArgsParser.Library/CommandAtlases/DownloadIcon/DownloadIconParameters.cs

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,29 @@
55
using CodeOfChaos.CliArgsParser.Contracts;
66

77
namespace CodeOfChaos.CliArgsParser.Library.CommandAtlases.DownloadIcon;
8-
98
// ---------------------------------------------------------------------------------------------------------------------
109
// Code
1110
// ---------------------------------------------------------------------------------------------------------------------
1211
public readonly partial struct DownloadIconParameters : IParameters {
13-
[CliArgsParameter("root", "r"), CliArgsDescription("The root directory of the project to update")]
12+
[CliArgsParameter("root", "r")] [CliArgsDescription("The root directory of the project to update")]
1413
public string Root { get; init; } = "../../../../../";
15-
16-
[CliArgsParameter("push", "p", ParameterType.Flag), CliArgsDescription("Push the changes to the remote repository")]
14+
15+
[CliArgsParameter("push", "p", ParameterType.Flag)] [CliArgsDescription("Push the changes to the remote repository")]
1716
public bool PushToRemote { get; init; } = false;
18-
19-
[CliArgsParameter("projects", "pr"), CliArgsDescription("The projects to update")]
17+
18+
[CliArgsParameter("projects", "pr")] [CliArgsDescription("The projects to update")]
2019
public required string ProjectsStringValue { get; init; }
21-
22-
[CliArgsParameter("project-split", "ps"), CliArgsDescription("The split character to use when splitting the projects string")]
20+
21+
[CliArgsParameter("project-split", "ps")] [CliArgsDescription("The split character to use when splitting the projects string")]
2322
public string ProjectsSplit { get; init; } = ";";
24-
25-
[CliArgsParameter("source-folder", "sf"), CliArgsDescription("The folder where the projects are located")]
23+
24+
[CliArgsParameter("source-folder", "sf")] [CliArgsDescription("The folder where the projects are located")]
2625
public string SourceFolder { get; init; } = "src";
27-
28-
[CliArgsParameter("icon-folder", "if"), CliArgsDescription("The folder where the icons are located")]
26+
27+
[CliArgsParameter("icon-folder", "if")] [CliArgsDescription("The folder where the icons are located")]
2928
public string IconFolder { get; init; } = "assets";
30-
31-
[CliArgsParameter("origin", "o"), CliArgsDescription("The origin of the icon file")]
29+
30+
[CliArgsParameter("origin", "o")] [CliArgsDescription("The origin of the icon file")]
3231
public required string Origin { get; init; }
3332

3433
public string[] GetProjects() => ProjectsStringValue

src/CodeOfChaos.CliArgsParser.Library/CommandAtlases/VersionBump/SemanticVersionDto.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
using System.Text.RegularExpressions;
66

77
namespace CodeOfChaos.CliArgsParser.Library.CommandAtlases.VersionBump;
8-
98
// ---------------------------------------------------------------------------------------------------------------------
109
// Code
1110
// ---------------------------------------------------------------------------------------------------------------------
@@ -14,14 +13,14 @@ public partial class SemanticVersionDto {
1413
private uint Minor { get; set; }
1514
private uint Patch { get; set; }
1615
private uint? Preview { get; set; }
17-
16+
1817
[GeneratedRegex(@"^(?<major>\d+)\.(?<minor>\d+)\.(?<patch>\d+)(-preview\.(?<preview>\d+))?$")]
1918
private static partial Regex FindVersionRegex { get; }
20-
19+
2120
// -----------------------------------------------------------------------------------------------------------------
2221
// Methods
2322
// -----------------------------------------------------------------------------------------------------------------
24-
public static bool TryParse(string version,[NotNullWhen(true)] out SemanticVersionDto? result) {
23+
public static bool TryParse(string version, [NotNullWhen(true)] out SemanticVersionDto? result) {
2524
Match match = FindVersionRegex.Match(version);
2625
if (!match.Success) {
2726
result = null;
@@ -34,6 +33,7 @@ public static bool TryParse(string version,[NotNullWhen(true)] out SemanticVersi
3433
Patch = uint.Parse(match.Groups["patch"].Value),
3534
Preview = match.Groups["preview"].Success ? uint.Parse(match.Groups["preview"].Value) : null
3635
};
36+
3737
return true;
3838
}
3939

@@ -71,8 +71,8 @@ public void BumpVersion(VersionSection section) {
7171
break;
7272
}
7373
}
74-
75-
public override string ToString() => Preview is not null
76-
? $"{Major}.{Minor}.{Patch}-preview.{Preview}"
74+
75+
public override string ToString() => Preview is not null
76+
? $"{Major}.{Minor}.{Patch}-preview.{Preview}"
7777
: $"{Major}.{Minor}.{Patch}";
7878
}

0 commit comments

Comments
 (0)