Skip to content

Commit a2a5907

Browse files
committed
Fix: Auto Code Cleanup
1 parent 43e2ffa commit a2a5907

File tree

14 files changed

+93
-89
lines changed

14 files changed

+93
-89
lines changed

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
<ProjectReference Include="..\CodeOfChaos.CliArgsParser\CodeOfChaos.CliArgsParser.csproj"/>
1313

1414
<!-- Ugly, but this is because of some weirdness with how analyzers are imported through a project reference -->
15-
<PackageReference Include="CodeOfChaos.GeneratorTools" Version="1.4.1" GeneratePathProperty="true" PrivateAssets="all" />
16-
<Analyzer Include="$(PkgCodeOfChaos_GeneratorTools)\lib\netstandard2.0\*.dll" />
15+
<PackageReference Include="CodeOfChaos.GeneratorTools" Version="1.4.1" GeneratePathProperty="true" PrivateAssets="all"/>
16+
<Analyzer Include="$(PkgCodeOfChaos_GeneratorTools)\lib\netstandard2.0\*.dll"/>
1717
</ItemGroup>
1818

1919
</Project>

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

+11-11
Original file line numberDiff line numberDiff line change
@@ -26,23 +26,23 @@
2626
</PropertyGroup>
2727

2828
<ItemGroup>
29-
<None Include="../../LICENSE" Pack="true" PackagePath="" Visible="false" />
30-
<None Include="../../README.md" Pack="true" PackagePath="" Visible="false" />
31-
<None Include="../../assets/icon.png" Pack="true" PackagePath="" Visible="false" />
29+
<None Include="../../LICENSE" Pack="true" PackagePath="" Visible="false"/>
30+
<None Include="../../README.md" Pack="true" PackagePath="" Visible="false"/>
31+
<None Include="../../assets/icon.png" Pack="true" PackagePath="" Visible="false"/>
3232
</ItemGroup>
3333

3434
<ItemGroup>
3535
<PackageReference Include="IsExternalInit" Version="1.0.3">
36-
<PrivateAssets>all</PrivateAssets>
37-
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
36+
<PrivateAssets>all</PrivateAssets>
37+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
3838
</PackageReference>
39-
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.11.0" PrivateAssets="all" />
40-
<PackageReference Include="Microsoft.CodeAnalysis.Common" Version="4.13.0" PrivateAssets="all" />
41-
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.13.0" PrivateAssets="all" />
42-
<PackageReference Include="CodeOfChaos.GeneratorTools" Version="1.4.1" Pack="true" GeneratePathProperty="true" PrivateAssets="all" />
39+
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.11.0" PrivateAssets="all"/>
40+
<PackageReference Include="Microsoft.CodeAnalysis.Common" Version="4.13.0" PrivateAssets="all"/>
41+
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.13.0" PrivateAssets="all"/>
42+
<PackageReference Include="CodeOfChaos.GeneratorTools" Version="1.4.1" Pack="true" GeneratePathProperty="true" PrivateAssets="all"/>
4343
</ItemGroup>
4444
<ItemGroup>
45-
<None Include="$(OutputPath)\$(AssemblyName).dll" Pack="true" PackagePath="analyzers/dotnet/cs" Visible="false" />
46-
<None Include="$(PkgCodeOfChaos_GeneratorTools)\lib\netstandard2.0\*.dll" Pack="true" PackagePath="analyzers/dotnet/cs" Visible="false" />
45+
<None Include="$(OutputPath)\$(AssemblyName).dll" Pack="true" PackagePath="analyzers/dotnet/cs" Visible="false"/>
46+
<None Include="$(PkgCodeOfChaos_GeneratorTools)\lib\netstandard2.0\*.dll" Pack="true" PackagePath="analyzers/dotnet/cs" Visible="false"/>
4747
</ItemGroup>
4848
</Project>

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ private static void GenerateSources(SourceProductionContext context, (Compilatio
6060
b.AppendLine();
6161
dto.ToCommandInitialization(b);
6262
b.AppendLine();
63-
} )
63+
})
6464
.AppendLine("}");
6565

6666
context.AddSource($"{dto.ClassName}.g.cs", builder.ToStringAndClear());

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ private static void GenerateSources(SourceProductionContext context, (Compilatio
6363
.AppendLine($"public partial struct {dto.ToDeclarationName()} {{")
6464
.Indent(b => {
6565
b.AppendLine($"public static {dto.ClassName} FromRegistry(IUserInputRegistry registry) => new() {{");
66-
b.ForEachAppendLineIndented(dto.PropertyDtos, propertyDto => propertyDto.ToPropertyInitialization());
66+
b.ForEachAppendLineIndented(dto.PropertyDtos, itemFormatter: propertyDto => propertyDto.ToPropertyInitialization());
6767
b.AppendLine("};");
6868
})
6969
.Indent(b => {
@@ -73,6 +73,7 @@ private static void GenerateSources(SourceProductionContext context, (Compilatio
7373
object boxed = FromRegistry(registry)!;
7474
return (T)boxed;
7575
""");
76+
7677
b.AppendLine("}");
7778
})
7879
.AppendLine("}");

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

+8-8
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,22 @@
2323
</PropertyGroup>
2424

2525
<ItemGroup>
26-
<None Include="../../LICENSE" Pack="true" PackagePath="" Visible="false" />
27-
<None Include="../../README.md" Pack="true" PackagePath="" Visible="false" />
28-
<None Include="../../assets/icon.png" Pack="true" PackagePath="" Visible="false" />
26+
<None Include="../../LICENSE" Pack="true" PackagePath="" Visible="false"/>
27+
<None Include="../../README.md" Pack="true" PackagePath="" Visible="false"/>
28+
<None Include="../../assets/icon.png" Pack="true" PackagePath="" Visible="false"/>
2929
</ItemGroup>
3030

3131
<ItemGroup>
3232
<!-- ProjectReference for the generator as an analyzer -->
33-
<ProjectReference Include="..\CodeOfChaos.CliArgsParser.Generators\CodeOfChaos.CliArgsParser.Generators.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
34-
<ProjectReference Include="..\CodeOfChaos.CliArgsParser\CodeOfChaos.CliArgsParser.csproj" />
33+
<ProjectReference Include="..\CodeOfChaos.CliArgsParser.Generators\CodeOfChaos.CliArgsParser.Generators.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false"/>
34+
<ProjectReference Include="..\CodeOfChaos.CliArgsParser\CodeOfChaos.CliArgsParser.csproj"/>
3535

3636
<!-- Ugly, but this is because of some weirdness with how analyzers are imported through a project reference -->
37-
<PackageReference Include="CodeOfChaos.GeneratorTools" Version="1.4.1" GeneratePathProperty="true" PrivateAssets="all" />
38-
<Analyzer Include="$(PkgCodeOfChaos_GeneratorTools)\lib\netstandard2.0\*.dll" />
37+
<PackageReference Include="CodeOfChaos.GeneratorTools" Version="1.4.1" GeneratePathProperty="true" PrivateAssets="all"/>
38+
<Analyzer Include="$(PkgCodeOfChaos_GeneratorTools)\lib\netstandard2.0\*.dll"/>
3939
</ItemGroup>
4040

4141
<ItemGroup>
42-
<PackageReference Include="CodeOfChaos.Ansi" Version="1.0.0" />
42+
<PackageReference Include="CodeOfChaos.Ansi" Version="1.0.0"/>
4343
</ItemGroup>
4444
</Project>

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

+36-36
Original file line numberDiff line numberDiff line change
@@ -101,52 +101,52 @@ private static async Task<bool> ApplyIcon(DownloadIconParameters args) {
101101
}
102102

103103
private static async Task<bool> TryGetIcon(DownloadIconParameters parameters) {
104-
105-
// Validate Origin
106-
if (string.IsNullOrWhiteSpace(parameters.Origin)) {
107-
Console.WriteLine(ConsoleTextStore.CommandEndFailure( "Error: The origin of the icon is not specified."));
108-
return false;
109-
}
110104

111-
// Assume Origin could be either a URL or a file path
112-
bool isUrl = Uri.TryCreate(parameters.Origin, UriKind.Absolute, out Uri? uriResult) && (uriResult.Scheme == Uri.UriSchemeHttp || uriResult.Scheme == Uri.UriSchemeHttps);
113-
114-
// Placeholder for the final icon's path
115-
string destinationPath = Path.Combine(parameters.Root, parameters.IconFolder, "icon.png");
105+
// Validate Origin
106+
if (string.IsNullOrWhiteSpace(parameters.Origin)) {
107+
Console.WriteLine(ConsoleTextStore.CommandEndFailure("Error: The origin of the icon is not specified."));
108+
return false;
109+
}
116110

117-
// create all folders if needed for the destination path
118-
Directory.CreateDirectory(Path.GetDirectoryName(destinationPath)!);
111+
// Assume Origin could be either a URL or a file path
112+
bool isUrl = Uri.TryCreate(parameters.Origin, UriKind.Absolute, out Uri? uriResult) && (uriResult.Scheme == Uri.UriSchemeHttp || uriResult.Scheme == Uri.UriSchemeHttps);
119113

120-
if (isUrl) {
121-
// Download the file from URL using HttpClient
122-
using var client = new HttpClient();
123-
Console.WriteLine($"Downloading icon from URL: {parameters.Origin}");
114+
// Placeholder for the final icon's path
115+
string destinationPath = Path.Combine(parameters.Root, parameters.IconFolder, "icon.png");
124116

125-
using HttpResponseMessage response = await client.GetAsync(parameters.Origin);
126-
if (!response.IsSuccessStatusCode) {
127-
Console.WriteLine(ConsoleTextStore.CommandEndFailure($"Error: Failed to download the icon. HTTP Status: {response.StatusCode}"));
128-
return false;
129-
}
117+
// create all folders if needed for the destination path
118+
Directory.CreateDirectory(Path.GetDirectoryName(destinationPath)!);
130119

131-
byte[] iconBytes = await response.Content.ReadAsByteArrayAsync();
132-
await File.WriteAllBytesAsync(destinationPath, iconBytes);
120+
if (isUrl) {
121+
// Download the file from URL using HttpClient
122+
using var client = new HttpClient();
123+
Console.WriteLine($"Downloading icon from URL: {parameters.Origin}");
133124

134-
Console.WriteLine($"Icon downloaded successfully to: {destinationPath}");
125+
using HttpResponseMessage response = await client.GetAsync(parameters.Origin);
126+
if (!response.IsSuccessStatusCode) {
127+
Console.WriteLine(ConsoleTextStore.CommandEndFailure($"Error: Failed to download the icon. HTTP Status: {response.StatusCode}"));
128+
return false;
135129
}
136-
else {
137-
// Treat as file system path and copy the icon
138-
Console.WriteLine($"Copying icon from local path: {parameters.Origin}");
139130

140-
if (!File.Exists(parameters.Origin)) {
141-
Console.WriteLine(ConsoleTextStore.CommandEndFailure($"Error: The specified origin file does not exist: {parameters.Origin}"));
142-
return false;
143-
}
131+
byte[] iconBytes = await response.Content.ReadAsByteArrayAsync();
132+
await File.WriteAllBytesAsync(destinationPath, iconBytes);
133+
134+
Console.WriteLine($"Icon downloaded successfully to: {destinationPath}");
135+
}
136+
else {
137+
// Treat as file system path and copy the icon
138+
Console.WriteLine($"Copying icon from local path: {parameters.Origin}");
144139

145-
File.Copy(parameters.Origin, destinationPath, true);
146-
Console.WriteLine($"Icon copied successfully to: {destinationPath}");
140+
if (!File.Exists(parameters.Origin)) {
141+
Console.WriteLine(ConsoleTextStore.CommandEndFailure($"Error: The specified origin file does not exist: {parameters.Origin}"));
142+
return false;
147143
}
148144

149-
// If all operations succeed
150-
return true;
145+
File.Copy(parameters.Origin, destinationPath, true);
146+
Console.WriteLine($"Icon copied successfully to: {destinationPath}");
147+
}
148+
149+
// If all operations succeed
150+
return true;
151151
}
152152
}

src/CodeOfChaos.CliArgsParser.Library/Commands/VersionBump/VersionBumpCommand.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public async Task ExecuteAsync(VersionBumpParameters parameters) {
2323
foreach (string message in ErrorMessages) Console.WriteLine(ConsoleTextStore.CommandEndFailure(message));
2424
return;
2525
}
26-
26+
2727
// Ask the user for extra input to make sure they want to commit and the current tag.
2828
if (!parameters.Force) {
2929
Console.WriteLine(ConsoleTextStore.QuestionTagAndCommit);
@@ -61,7 +61,7 @@ public async Task ExecuteAsync(VersionBumpParameters parameters) {
6161
Console.WriteLine(ConsoleTextStore.CommandEndFailure("Git Pushing failed"));
6262
return;
6363
}
64-
64+
6565
bool pushTagsResult = await GitHelpers.TryPushTagsToOrigin();
6666
if (!pushTagsResult) {
6767
Console.WriteLine(ConsoleTextStore.CommandEndFailure("Git Pushing Tags failed"));

src/CodeOfChaos.CliArgsParser.Library/Shared/ConsoleTextStore.cs

+7-8
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using CodeOfChaos.Ansi;
55

66
namespace CodeOfChaos.CliArgsParser.Library.Shared;
7-
87
// ---------------------------------------------------------------------------------------------------------------------
98
// Code
109
// ---------------------------------------------------------------------------------------------------------------------
@@ -15,32 +14,32 @@ public static class ConsoleTextStore {
1514
.AppendWhitesmoke("Defining and Bumping version ")
1615
.AppendSlategray("...")
1716
.ToStringAndClear();
18-
17+
1918
public static string GitCommitting => Builder.Fore
2019
.AppendWhitesmoke("Git committing ")
2120
.AppendSlategray("...")
2221
.ToStringAndClear();
23-
22+
2423
public static string GitTagging => Builder.Fore
2524
.AppendWhitesmoke("Git tagging ")
2625
.AppendSlategray("...")
2726
.ToStringAndClear();
28-
27+
2928
public static string GitPushingToRemote => Builder.Fore
3029
.AppendWhitesmoke("Pushing to origin ")
3130
.AppendSlategray("...")
3231
.ToStringAndClear();
33-
32+
3433
public static string QuestionTagAndCommit => Builder
3534
.WithFore(f => f
3635
.AppendWhitesmoke("Do you want to Git tag & push to origin?")
3736
.AppendSlategray(" (y/n)")
3837
).ToStringAndClear();
39-
38+
4039
public static string CommandEndSuccess() => Builder.Fore
4140
.AppendGreen("Command completed successfully.")
4241
.ToStringAndClear();
43-
42+
4443
public static string CommandEndFailure(string? failure) => Builder.Fore
4544
.WithFore(f => {
4645
f.AppendCrimson("Command failed");
@@ -53,7 +52,7 @@ public static string TagSuccessful(SemanticVersionDto versionDto) => Builder
5352
.AppendDeepskyblue(versionDto.ToString())
5453
.AppendWhitesmoke(" successfully git tagged and committed.")
5554
).ToStringAndClear();
56-
55+
5756
public static string UpdatedVersion(string projectName, string versionElement) => Builder
5857
.WithFore(f => f
5958
.AppendWhitesmoke("Updated version of package ")

src/CodeOfChaos.CliArgsParser.Library/Shared/CsProjHelpers.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public static async IAsyncEnumerable<XDocument> GetProjectFiles(string[] project
1919
IndentChars = " ",
2020
Async = true,
2121
OmitXmlDeclaration = true,
22-
NewLineOnAttributes = false // Keeps attributes on the same line
22+
NewLineOnAttributes = false// Keeps attributes on the same line
2323
};
2424

2525
foreach (string path in projectPaths) {

src/CodeOfChaos.CliArgsParser.Library/Shared/GitHelpers.cs

+12-8
Original file line numberDiff line numberDiff line change
@@ -15,51 +15,54 @@ public static async Task<bool> TryPushToOrigin() {
1515
UseShellExecute = false,
1616
CreateNoWindow = true
1717
};
18+
1819
var builder = new AnsiStringBuilder();
1920

2021
using Process? gitTagProcess = Process.Start(gitTagInfo);
2122

2223
builder.Fore.AppendWhitesmokeLine(await gitTagProcess?.StandardOutput.ReadToEndAsync()!);
2324
Console.WriteLine(builder.ToStringAndClear());
24-
25+
2526
await gitTagProcess.WaitForExitAsync();
2627

2728
return gitTagProcess.ExitCode == 0;
2829
}
29-
30-
30+
31+
3132
public static async Task<bool> TryPushTagsToOrigin() {
3233
var gitTagInfo = new ProcessStartInfo("git", "push origin --tags") {
3334
RedirectStandardOutput = true,
3435
UseShellExecute = false,
3536
CreateNoWindow = true
3637
};
38+
3739
var builder = new AnsiStringBuilder();
3840

3941
using Process? gitTagProcess = Process.Start(gitTagInfo);
4042

4143
builder.Fore.AppendWhitesmokeLine(await gitTagProcess?.StandardOutput.ReadToEndAsync()!);
4244
Console.WriteLine(builder.ToStringAndClear());
43-
45+
4446
await gitTagProcess.WaitForExitAsync();
45-
47+
4648
return gitTagProcess.ExitCode == 0;
4749
}
48-
50+
4951

5052
public static async Task<bool> TryCreateGitTag(SemanticVersionDto updatedVersion) {
5153
var gitTagInfo = new ProcessStartInfo("git", "tag v" + updatedVersion) {
5254
RedirectStandardOutput = true,
5355
UseShellExecute = false,
5456
CreateNoWindow = true
5557
};
58+
5659
var builder = new AnsiStringBuilder();
5760

5861
using Process? gitTagProcess = Process.Start(gitTagInfo);
5962

6063
builder.Fore.AppendWhitesmokeLine(await gitTagProcess?.StandardOutput.ReadToEndAsync()!);
6164
Console.WriteLine(builder.ToStringAndClear());
62-
65+
6366
await gitTagProcess.WaitForExitAsync();
6467

6568
return gitTagProcess.ExitCode == 0;
@@ -71,13 +74,14 @@ public static async Task<bool> TryCreateGitCommit(SemanticVersionDto updatedVers
7174
UseShellExecute = false,
7275
CreateNoWindow = true
7376
};
77+
7478
var builder = new AnsiStringBuilder();
7579

7680
using Process? gitCommitProcess = Process.Start(gitCommitInfo);
7781

7882
builder.Fore.AppendWhitesmokeLine(await gitCommitProcess?.StandardOutput.ReadToEndAsync()!);
7983
Console.WriteLine(builder.ToStringAndClear());
80-
84+
8185
await gitCommitProcess.WaitForExitAsync();
8286

8387
return gitCommitProcess.ExitCode == 0;

src/CodeOfChaos.CliArgsParser.Library/Shared/SemanticVersionDto.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,11 @@ public void BumpVersion(VersionSection section) {
6464

6565
case VersionSection.Preview when Preview is null: {
6666
SemanticVersionDto newVersion = FromInput("Please enter a semantic version for the new preview version:");
67-
67+
6868
Major = newVersion.Major;
6969
Minor = newVersion.Minor;
7070
Patch = newVersion.Patch;
71-
Preview = newVersion.Preview ?? 0 ;
71+
Preview = newVersion.Preview ?? 0;
7272
return;
7373
}
7474

@@ -79,7 +79,7 @@ public void BumpVersion(VersionSection section) {
7979

8080
case VersionSection.Manual: {
8181
SemanticVersionDto newVersion = FromInput();
82-
82+
8383
Major = newVersion.Major;
8484
Minor = newVersion.Minor;
8585
Patch = newVersion.Patch;

src/CodeOfChaos.CliArgsParser/CodeOfChaos.CliArgsParser.csproj

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@
2222
</PropertyGroup>
2323

2424
<ItemGroup>
25-
<None Include="../../LICENSE" Pack="true" PackagePath="" Visible="false" />
26-
<None Include="../../README.md" Pack="true" PackagePath="" Visible="false" />
27-
<None Include="../../assets/icon.png" Pack="true" PackagePath="" Visible="false" />
25+
<None Include="../../LICENSE" Pack="true" PackagePath="" Visible="false"/>
26+
<None Include="../../README.md" Pack="true" PackagePath="" Visible="false"/>
27+
<None Include="../../assets/icon.png" Pack="true" PackagePath="" Visible="false"/>
2828
</ItemGroup>
2929

3030
</Project>

0 commit comments

Comments
 (0)