11// ---------------------------------------------------------------------------------------------------------------------
22// Imports
33// ---------------------------------------------------------------------------------------------------------------------
4- using AterraEngine . Unions ;
54using CodeOfChaos . CliArgsParser . Library . Shared ;
65using 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." ) ]
1413public 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}
0 commit comments