Skip to content

Commit 43e2ffa

Browse files
committed
Change: Remove AterraEngine.Unions dependency
Yeah it is a great library, but I want to stop updating this package every time I update Unions
1 parent b41caae commit 43e2ffa

File tree

4 files changed

+56
-65
lines changed

4 files changed

+56
-65
lines changed

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
</ItemGroup>
4040

4141
<ItemGroup>
42-
<PackageReference Include="AterraEngine.Unions" Version="4.0.1" />
4342
<PackageReference Include="CodeOfChaos.Ansi" Version="1.0.0" />
4443
</ItemGroup>
4544
</Project>

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

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// ---------------------------------------------------------------------------------------------------------------------
22
// Imports
33
// ---------------------------------------------------------------------------------------------------------------------
4-
using AterraEngine.Unions;
54
using CodeOfChaos.CliArgsParser.Library.Shared;
65
using System.Text.RegularExpressions;
76
using System.Xml.Linq;
@@ -22,24 +21,27 @@ public partial class DownloadIconCommand : ICommand<DownloadIconParameters> {
2221
// -----------------------------------------------------------------------------------------------------------------
2322
public async Task ExecuteAsync(DownloadIconParameters parameters) {
2423
Console.WriteLine("Downloading Icon...");
25-
SuccessOrFailure getResult = await TryGetIcon(parameters);
26-
if (getResult is { IsFailure: true, AsFailure.Value: var getError }) {
27-
Console.WriteLine(getError);
24+
bool getResult = await TryGetIcon(parameters);
25+
if (!getResult) {
26+
Console.WriteLine(ConsoleTextStore.CommandEndFailure("Could not download icon."));
27+
return;
2828
}
2929

3030
Console.WriteLine("Icon downloaded successfully.");
31-
SuccessOrFailure applyResult = await ApplyIcon(parameters);
32-
if (applyResult is { IsFailure: true, AsFailure.Value: var applyError }) {
33-
Console.WriteLine(applyError);
31+
bool applyResult = await ApplyIcon(parameters);
32+
if (!applyResult) {
33+
Console.WriteLine(ConsoleTextStore.CommandEndFailure("Could not apply icon."));
34+
return;
3435
}
3536

3637
Console.WriteLine("Icon applied successfully.");
3738
}
3839

39-
private static async Task<SuccessOrFailure> ApplyIcon(DownloadIconParameters args) {
40+
private static async Task<bool> ApplyIcon(DownloadIconParameters args) {
4041
string[] projectFiles = CsProjHelpers.AsProjectPaths(args.Root, args.SourceFolder, args.GetProjects());
4142
if (projectFiles.Length == 0) {
42-
return new Failure<string>("No projects specified");
43+
Console.WriteLine(ConsoleTextStore.CommandEndFailure("No projects specified"));
44+
return false;
4345
}
4446

4547
await foreach (XDocument document in CsProjHelpers.GetProjectFiles(projectFiles)) {
@@ -95,14 +97,15 @@ private static async Task<SuccessOrFailure> ApplyIcon(DownloadIconParameters arg
9597
}
9698
}
9799

98-
return new Success();
100+
return true;
99101
}
100102

101-
private static async Task<SuccessOrFailure> TryGetIcon(DownloadIconParameters parameters) {
102-
try {
103+
private static async Task<bool> TryGetIcon(DownloadIconParameters parameters) {
104+
103105
// Validate Origin
104106
if (string.IsNullOrWhiteSpace(parameters.Origin)) {
105-
return "Error: The origin of the icon is not specified.";
107+
Console.WriteLine(ConsoleTextStore.CommandEndFailure( "Error: The origin of the icon is not specified."));
108+
return false;
106109
}
107110

108111
// Assume Origin could be either a URL or a file path
@@ -121,7 +124,8 @@ private static async Task<SuccessOrFailure> TryGetIcon(DownloadIconParameters pa
121124

122125
using HttpResponseMessage response = await client.GetAsync(parameters.Origin);
123126
if (!response.IsSuccessStatusCode) {
124-
return $"Error: Failed to download the icon. HTTP Status: {response.StatusCode}";
127+
Console.WriteLine(ConsoleTextStore.CommandEndFailure($"Error: Failed to download the icon. HTTP Status: {response.StatusCode}"));
128+
return false;
125129
}
126130

127131
byte[] iconBytes = await response.Content.ReadAsByteArrayAsync();
@@ -134,19 +138,15 @@ private static async Task<SuccessOrFailure> TryGetIcon(DownloadIconParameters pa
134138
Console.WriteLine($"Copying icon from local path: {parameters.Origin}");
135139

136140
if (!File.Exists(parameters.Origin)) {
137-
return $"Error: The specified origin file does not exist: {parameters.Origin}";
141+
Console.WriteLine(ConsoleTextStore.CommandEndFailure($"Error: The specified origin file does not exist: {parameters.Origin}"));
142+
return false;
138143
}
139144

140145
File.Copy(parameters.Origin, destinationPath, true);
141146
Console.WriteLine($"Icon copied successfully to: {destinationPath}");
142147
}
143148

144149
// If all operations succeed
145-
return new Success();
146-
}
147-
catch (Exception ex) {
148-
// Return any unexpected errors
149-
return $"Unexpected error: {ex.Message}";
150-
}
150+
return true;
151151
}
152152
}

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

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// ---------------------------------------------------------------------------------------------------------------------
22
// Imports
33
// ---------------------------------------------------------------------------------------------------------------------
4-
using AterraEngine.Unions;
54
using CodeOfChaos.CliArgsParser.Library.Shared;
65
using System.Xml.Linq;
76

@@ -12,19 +11,18 @@ namespace CodeOfChaos.CliArgsParser.Library.Commands.VersionBump;
1211
[CliArgsCommand("git-version-bump")]
1312
[CliArgsDescription("Bumps the version of the projects specified in the projects argument.")]
1413
public partial class VersionBumpCommand : ICommand<VersionBumpParameters> {
14+
private static readonly List<string> ErrorMessages = [];
1515

1616
// -----------------------------------------------------------------------------------------------------------------
1717
// Methods
1818
// -----------------------------------------------------------------------------------------------------------------
1919
public async Task ExecuteAsync(VersionBumpParameters parameters) {
2020
Console.WriteLine(ConsoleTextStore.BumpingVersion);
21-
SuccessOrFailure<SemanticVersionDto> bumpResult = await BumpVersion(parameters);
22-
if (bumpResult is { IsFailure: true, AsFailure.Value: var errorBumping }) {
23-
Console.WriteLine(ConsoleTextStore.CommandEndFailure(errorBumping));
21+
SemanticVersionDto? updatedVersion = await BumpVersion(parameters);
22+
if (updatedVersion is null) {
23+
foreach (string message in ErrorMessages) Console.WriteLine(ConsoleTextStore.CommandEndFailure(message));
2424
return;
2525
}
26-
27-
SemanticVersionDto updatedVersion = bumpResult.AsSuccess.Value;
2826

2927
// Ask the user for extra input to make sure they want to commit and the current tag.
3028
if (!parameters.Force) {
@@ -37,16 +35,16 @@ public async Task ExecuteAsync(VersionBumpParameters parameters) {
3735
}
3836

3937
Console.WriteLine(ConsoleTextStore.GitCommitting);
40-
SuccessOrFailure gitCommitResult = await GitHelpers.TryCreateGitCommit(updatedVersion);
41-
if (gitCommitResult is { IsFailure: true, AsFailure.Value: var errorCommiting }) {
42-
Console.WriteLine(ConsoleTextStore.CommandEndFailure(errorCommiting));
38+
bool gitCommitResult = await GitHelpers.TryCreateGitCommit(updatedVersion);
39+
if (!gitCommitResult) {
40+
Console.WriteLine(ConsoleTextStore.CommandEndFailure("Git Committing failed"));
4341
return;
4442
}
4543

4644
Console.WriteLine(ConsoleTextStore.GitTagging);
47-
SuccessOrFailure gitTagResult = await GitHelpers.TryCreateGitTag(updatedVersion);
48-
if (gitTagResult is { IsFailure: true, AsFailure.Value: var errorTagging }) {
49-
Console.WriteLine(ConsoleTextStore.CommandEndFailure(errorTagging));
45+
bool gitTagResult = await GitHelpers.TryCreateGitTag(updatedVersion);
46+
if (!gitTagResult) {
47+
Console.WriteLine(ConsoleTextStore.CommandEndFailure("Git Tagging failed"));
5048
return;
5149
}
5250

@@ -58,26 +56,27 @@ public async Task ExecuteAsync(VersionBumpParameters parameters) {
5856
}
5957

6058
Console.WriteLine(ConsoleTextStore.GitPushingToRemote);
61-
SuccessOrFailure pushResult = await GitHelpers.TryPushToOrigin();
62-
if (pushResult is { IsFailure: true, AsFailure.Value: var errorPushing }) {
63-
Console.WriteLine(ConsoleTextStore.CommandEndFailure(errorPushing));
59+
bool pushResult = await GitHelpers.TryPushToOrigin();
60+
if (!pushResult) {
61+
Console.WriteLine(ConsoleTextStore.CommandEndFailure("Git Pushing failed"));
6462
return;
6563
}
6664

67-
SuccessOrFailure pushTagsResult = await GitHelpers.TryPushTagsToOrigin();
68-
if (pushTagsResult is { IsFailure: true, AsFailure.Value: var errorPushingTags }) {
69-
Console.WriteLine(ConsoleTextStore.CommandEndFailure(errorPushingTags));
65+
bool pushTagsResult = await GitHelpers.TryPushTagsToOrigin();
66+
if (!pushTagsResult) {
67+
Console.WriteLine(ConsoleTextStore.CommandEndFailure("Git Pushing Tags failed"));
7068
return;
7169
}
7270

7371
Console.WriteLine(ConsoleTextStore.CommandEndSuccess());
7472
}
7573

7674

77-
private static async Task<SuccessOrFailure<SemanticVersionDto>> BumpVersion(VersionBumpParameters args) {
75+
private static async Task<SemanticVersionDto?> BumpVersion(VersionBumpParameters args) {
7876
string[] projectFiles = CsProjHelpers.AsProjectPaths(args.Root, args.SourceFolder, args.GetProjects());
7977
if (projectFiles.Length == 0) {
80-
return new Failure<string>("No projects specified");
78+
ErrorMessages.Add("No projects specified");
79+
return null;
8180
}
8281

8382
VersionSection sectionToBump = args.Section;
@@ -97,12 +96,15 @@ private static async Task<SuccessOrFailure<SemanticVersionDto>> BumpVersion(Vers
9796
.Value ?? "UNKNOWN";
9897

9998
if (versionElement == null) {
100-
return new Failure<string>("File did not contain a version element");
99+
ErrorMessages.Add($"File {projectName} did not contain a version element");
100+
continue;
101101
}
102102

103103
if (versionDto is null) {
104-
if (!SemanticVersionDto.TryParse(versionElement.Value, out SemanticVersionDto? dto))
105-
return new Failure<string>($"File contained an invalid version element: {versionElement.Value}");
104+
if (!SemanticVersionDto.TryParse(versionElement.Value, out SemanticVersionDto? dto)) {
105+
ErrorMessages.Add($"File {projectName} contained an invalid version element: {versionElement.Value}");
106+
continue;
107+
}
106108

107109
dto.BumpVersion(sectionToBump);
108110

@@ -113,8 +115,6 @@ private static async Task<SuccessOrFailure<SemanticVersionDto>> BumpVersion(Vers
113115
Console.WriteLine(ConsoleTextStore.UpdatedVersion(projectName, versionElement.Value));
114116
}
115117

116-
return versionDto is not null
117-
? new Success<SemanticVersionDto>(versionDto)
118-
: new Failure<string>("Could not find a version to bump");
118+
return versionDto;
119119
}
120120
}

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

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// ---------------------------------------------------------------------------------------------------------------------
22
// Imports
33
// ---------------------------------------------------------------------------------------------------------------------
4-
using AterraEngine.Unions;
54
using CodeOfChaos.Ansi;
65
using System.Diagnostics;
76

@@ -10,7 +9,7 @@ namespace CodeOfChaos.CliArgsParser.Library.Shared;
109
// Code
1110
// ---------------------------------------------------------------------------------------------------------------------
1211
public static class GitHelpers {
13-
public static async Task<SuccessOrFailure> TryPushToOrigin() {
12+
public static async Task<bool> TryPushToOrigin() {
1413
var gitTagInfo = new ProcessStartInfo("git", "push origin") {
1514
RedirectStandardOutput = true,
1615
UseShellExecute = false,
@@ -25,13 +24,11 @@ public static async Task<SuccessOrFailure> TryPushToOrigin() {
2524

2625
await gitTagProcess.WaitForExitAsync();
2726

28-
if (gitTagProcess.ExitCode != 0) return "Push to origin failed";
29-
30-
return new Success();
27+
return gitTagProcess.ExitCode == 0;
3128
}
3229

3330

34-
public static async Task<SuccessOrFailure> TryPushTagsToOrigin() {
31+
public static async Task<bool> TryPushTagsToOrigin() {
3532
var gitTagInfo = new ProcessStartInfo("git", "push origin --tags") {
3633
RedirectStandardOutput = true,
3734
UseShellExecute = false,
@@ -45,14 +42,12 @@ public static async Task<SuccessOrFailure> TryPushTagsToOrigin() {
4542
Console.WriteLine(builder.ToStringAndClear());
4643

4744
await gitTagProcess.WaitForExitAsync();
48-
49-
if (gitTagProcess.ExitCode != 0) return "Pushing Tags to origin failed";
50-
51-
return new Success();
45+
46+
return gitTagProcess.ExitCode == 0;
5247
}
5348

5449

55-
public static async Task<SuccessOrFailure> TryCreateGitTag(SemanticVersionDto updatedVersion) {
50+
public static async Task<bool> TryCreateGitTag(SemanticVersionDto updatedVersion) {
5651
var gitTagInfo = new ProcessStartInfo("git", "tag v" + updatedVersion) {
5752
RedirectStandardOutput = true,
5853
UseShellExecute = false,
@@ -67,12 +62,10 @@ public static async Task<SuccessOrFailure> TryCreateGitTag(SemanticVersionDto up
6762

6863
await gitTagProcess.WaitForExitAsync();
6964

70-
if (gitTagProcess.ExitCode != 0) return "Git Tagging failed";
71-
72-
return new Success();
65+
return gitTagProcess.ExitCode == 0;
7366
}
7467

75-
public static async Task<SuccessOrFailure> TryCreateGitCommit(SemanticVersionDto updatedVersion) {
68+
public static async Task<bool> TryCreateGitCommit(SemanticVersionDto updatedVersion) {
7669
var gitCommitInfo = new ProcessStartInfo("git", $"commit -am \"VersionBump : v{updatedVersion}\"") {
7770
RedirectStandardOutput = true,
7871
UseShellExecute = false,
@@ -87,8 +80,7 @@ public static async Task<SuccessOrFailure> TryCreateGitCommit(SemanticVersionDto
8780

8881
await gitCommitProcess.WaitForExitAsync();
8982

90-
if (gitCommitProcess.ExitCode != 0) return "Git Commit failed";
83+
return gitCommitProcess.ExitCode == 0;
9184

92-
return new Success();
9385
}
9486
}

0 commit comments

Comments
 (0)