Skip to content

Commit ce25222

Browse files
committed
Feat: Fully working download icon
1 parent 8c0fac9 commit ce25222

File tree

6 files changed

+41
-32
lines changed

6 files changed

+41
-32
lines changed
Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
<Project Sdk="Microsoft.NET.Sdk">
2-
32
<PropertyGroup>
43
<TargetFramework>netstandard2.0</TargetFramework>
54
<IsPackable>true</IsPackable>
65
<Nullable>enable</Nullable>
76
<LangVersion>latest</LangVersion>
8-
97
<DevelopmentDependency>true</DevelopmentDependency>
108
<EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules>
119
<IsRoslynComponent>true</IsRoslynComponent>
12-
1310
<IsPackable>true</IsPackable>
11+
12+
<!-- Main package name -->
1413
<PackageId>CodeOfChaos.CliArgsParser.Generators</PackageId>
15-
<Version>3.0.3-preview.5</Version> <!-- Package version -->
14+
<Version>3.0.3-preview.5</Version>
1615
<Authors>Anna Sas</Authors>
1716
<Description>CliArgsParser is a library built around Dependency Injection to allow you to create CLI tools with ease</Description>
1817
<PackageProjectUrl>https://github.com/code-of-chaos/cs-code_of_chaos-cli_args_parser/</PackageProjectUrl>
@@ -25,13 +24,13 @@
2524
<PackageReadmeFile>README.md</PackageReadmeFile>
2625
<PackageIcon>icon.png</PackageIcon>
2726
</PropertyGroup>
28-
27+
2928
<ItemGroup>
3029
<None Include="..\..\LICENSE" Pack="true" PackagePath="" />
3130
<None Include="..\..\README.md" Pack="true" PackagePath="" />
32-
<None Include="icon.png" Pack="true" PackagePath="" />
31+
<None Include="../../assets/icon.png" Pack="true" PackagePath="" />
3332
</ItemGroup>
34-
33+
3534
<ItemGroup>
3635
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.11.0">
3736
<PrivateAssets>all</PrivateAssets>
@@ -40,10 +39,7 @@
4039
<PackageReference Include="Microsoft.CodeAnalysis.Common" Version="4.12.0" />
4140
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.12.0" />
4241
</ItemGroup>
43-
4442
<ItemGroup>
4543
<None Include="$(OutputPath)\$(AssemblyName).dll" Pack="true" PackagePath="analyzers/dotnet/cs" Visible="false" />
4644
</ItemGroup>
47-
48-
49-
</Project>
45+
</Project>
Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
<Project Sdk="Microsoft.NET.Sdk">
2-
32
<PropertyGroup>
43
<TargetFramework>net9.0</TargetFramework>
54
<LangVersion>latest</LangVersion>
65
<ImplicitUsings>enable</ImplicitUsings>
76
<Nullable>enable</Nullable>
8-
97
<IsPackable>true</IsPackable>
10-
<PackageId>CodeOfChaos.CliArgsParser.Library</PackageId> <!-- Main package name -->
11-
<Version>3.0.3-preview.5</Version> <!-- Package version -->
8+
9+
<!-- Main package name -->
10+
<PackageId>CodeOfChaos.CliArgsParser.Library</PackageId>
11+
<Version>3.0.3-preview.5</Version>
1212
<Authors>Anna Sas</Authors>
1313
<Description>CliArgsParser is a library built around Dependency Injection to allow you to create CLI tools with ease</Description>
1414
<PackageProjectUrl>https://github.com/code-of-chaos/cs-code_of_chaos-cli_args_parser/</PackageProjectUrl>
@@ -21,21 +21,20 @@
2121
<PackageReadmeFile>README.md</PackageReadmeFile>
2222
<PackageIcon>icon.png</PackageIcon>
2323
</PropertyGroup>
24-
24+
2525
<ItemGroup>
2626
<None Include="..\..\LICENSE" Pack="true" PackagePath="" />
2727
<None Include="..\..\README.md" Pack="true" PackagePath="" />
2828
<None Include="..\..\assets/icon.png" Pack="true" PackagePath="" />
2929
</ItemGroup>
30-
30+
3131
<ItemGroup>
3232
<ProjectReference Include="..\CodeOfChaos.CliArgsParser.Generators\CodeOfChaos.CliArgsParser.Generators.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
3333
<ProjectReference Include="..\CodeOfChaos.CliArgsParser\CodeOfChaos.CliArgsParser.csproj" />
3434
</ItemGroup>
35-
35+
3636
<ItemGroup>
3737
<PackageReference Include="AterraEngine.Unions" Version="2.5.0" />
3838
<PackageReference Include="CodeOfChaos.Ansi" Version="0.1.7" />
3939
</ItemGroup>
40-
41-
</Project>
40+
</Project>

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using CodeOfChaos.CliArgsParser.Attributes;
66
using CodeOfChaos.CliArgsParser.Contracts;
77
using CodeOfChaos.CliArgsParser.Library.Shared;
8+
using System.Text.RegularExpressions;
89
using System.Xml.Linq;
910

1011
namespace CodeOfChaos.CliArgsParser.Library.CommandAtlases.DownloadIcon;
@@ -73,9 +74,17 @@ private static async Task<SuccessOrFailure> ApplyIcon(DownloadIconParameters arg
7374

7475
if (iconExists) continue;
7576

77+
IEnumerable<string> indents = Enumerable.Repeat(
78+
"../",
79+
1
80+
+ (IsEmptyFolderNameRegex.IsMatch(args.SourceFolder) ? 1 : 0)
81+
+ args.SourceFolder.Count(c => c is '/' or '\\')
82+
);
83+
string includeString = Path.Combine(string.Join(string.Empty,indents),args.IconFolder, "icon.png");
84+
7685
// Add the icon.png reference if it doesn't exist
7786
var newIconElement = new XElement("None",
78-
new XAttribute("Include", "icon.png"),
87+
new XAttribute("Include", includeString),
7988
new XAttribute("Pack", "true"),
8089
new XAttribute("PackagePath", ""));
8190
packableItemGroup.Add(newIconElement);
@@ -134,4 +143,6 @@ private static async Task<SuccessOrFailure> TryGetIcon(DownloadIconParameters pa
134143
}
135144
}
136145

146+
[GeneratedRegex(@"^[^/\\\s]+$")]
147+
private static partial Regex IsEmptyFolderNameRegex { get; }
137148
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ namespace CodeOfChaos.CliArgsParser.Library.CommandAtlases.DownloadIcon;
2525
public string SourceFolder { get; init; } = "src";
2626

2727
[CliArgsParameter("icon-folder", "if")] [CliArgsDescription("The folder where the icons are located")]
28-
public string IconFolder { get; init; } = "assets";
28+
public string IconFolder { get; init; } = "assets/";
2929

3030
[CliArgsParameter("origin", "o")] [CliArgsDescription("The origin of the icon file")]
3131
public required string Origin { get; init; }

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,27 @@ public static async IAsyncEnumerable<XDocument> GetProjectFiles(string[] project
1919
Indent = true,
2020
IndentChars = " ",
2121
Async = true,
22-
OmitXmlDeclaration = true
22+
OmitXmlDeclaration = true,
23+
NewLineOnAttributes = false // Keeps attributes on the same line
2324
};
2425

2526
foreach (string path in projectPaths) {
2627
if (!File.Exists(path)) {
2728
throw new FileNotFoundException($"Could not find project file {path}");
2829
}
2930

31+
// Load with PreserveWhitespace to retain empty lines
3032
XDocument document;
3133
await using (var stream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read, 4096, true)) {
3234
document = await XDocument.LoadAsync(stream, LoadOptions.PreserveWhitespace, CancellationToken.None);
3335
}
3436

3537
yield return document;
3638

39+
// Save using XmlWriter to apply consistent indentation, but preserve empty lines
3740
await using (var stream = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.None, 4096, true)) {
3841
await using var writer = XmlWriter.Create(stream, settings);
39-
document.Save(writer);
42+
document.Save(writer); // Save while enforcing indentation
4043
}
4144
}
4245
}
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
<Project Sdk="Microsoft.NET.Sdk">
2-
32
<PropertyGroup>
43
<TargetFramework>net9.0</TargetFramework>
54
<ImplicitUsings>enable</ImplicitUsings>
65
<Nullable>enable</Nullable>
7-
86
<IsPackable>true</IsPackable>
9-
<PackageId>CodeOfChaos.CliArgsParser</PackageId> <!-- Main package name -->
10-
<Version>3.0.3-preview.5</Version> <!-- Package version -->
7+
8+
<!-- Main package name -->
9+
<PackageId>CodeOfChaos.CliArgsParser</PackageId>
10+
<Version>3.0.3-preview.5</Version>
1111
<Authors>Anna Sas</Authors>
1212
<Description>CliArgsParser is a library built around Dependency Injection to allow you to create CLI tools with ease</Description>
1313
<PackageProjectUrl>https://github.com/code-of-chaos/cs-code_of_chaos-cli_args_parser/</PackageProjectUrl>
@@ -20,11 +20,11 @@
2020
<PackageReadmeFile>README.md</PackageReadmeFile>
2121
<PackageIcon>icon.png</PackageIcon>
2222
</PropertyGroup>
23-
23+
2424
<ItemGroup>
2525
<None Include="..\..\LICENSE" Pack="true" PackagePath="" />
2626
<None Include="..\..\README.md" Pack="true" PackagePath="" />
27-
<None Include="..\..\assets/icon.png" Pack="true" PackagePath="" />
27+
<None Include="../../assets/icon.png" Pack="true" PackagePath="" />
2828
</ItemGroup>
29-
30-
</Project>
29+
30+
</Project>

0 commit comments

Comments
 (0)