diff --git a/GitTools.sln b/GitTools.sln index 7245986..d6b018b 100644 --- a/GitTools.sln +++ b/GitTools.sln @@ -20,8 +20,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "source", "source", "{35D676 Directory.Build.props = source\Directory.Build.props EndProjectSection EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Commands", "Commands", "{4AD18751-E2F6-40F3-99F6-69FA2320CA30}" -EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CreativeCoders.Git.Abstractions", "source\Git\CreativeCoders.Git.Abstractions\CreativeCoders.Git.Abstractions.csproj", "{AD6C98CD-A96D-4795-B9A7-F321D6597C11}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CreativeCoders.Git.Auth.CredentialManagerCore", "source\Git\CreativeCoders.Git.Auth.CredentialManagerCore\CreativeCoders.Git.Auth.CredentialManagerCore.csproj", "{0858E655-2326-48F6-85FA-01E068A0331F}" @@ -34,12 +32,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CreativeCoders.GitTool.GitH EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CreativeCoders.GitTool.GitLab", "source\GitTool\CreativeCoders.GitTool.GitLab\CreativeCoders.GitTool.GitLab.csproj", "{F79BE247-8C60-4A51-B538-B2387C2D357F}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CreativeCoders.GitTool.Commands.Branches", "source\GitTool\Commands\CreativeCoders.GitTool.Commands.Branches\CreativeCoders.GitTool.Commands.Branches.csproj", "{1589F267-9A07-470B-A13C-9FE1CE5016B5}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CreativeCoders.GitTool.Commands.Features", "source\GitTool\Commands\CreativeCoders.GitTool.Commands.Features\CreativeCoders.GitTool.Commands.Features.csproj", "{0B7EBFC9-9D04-4F2C-8B63-387F2A2AAAD9}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CreativeCoders.GitTool.Cli", "source\GitTool\CreativeCoders.GitTool.Cli\CreativeCoders.GitTool.Cli.csproj", "{35C347B1-6DA0-4D9F-8259-928C561EEF8C}" -EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CreativeCoders.Git.Auth.CredentialManagerCore.UnitTests", "tests\CreativeCoders.Git.Auth.CredentialManagerCore.UnitTests\CreativeCoders.Git.Auth.CredentialManagerCore.UnitTests.csproj", "{0E6E1AE1-7176-4D40-96AE-7A9FDC4D3223}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CreativeCoders.Git.UnitTests", "tests\CreativeCoders.Git.UnitTests\CreativeCoders.Git.UnitTests.csproj", "{8E5F6024-5850-4272-9A9D-45CF566C526A}" @@ -48,14 +40,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CreativeCoders.GitTool.GitH EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CreativeCoders.GitTool.GitLab.UnitTests", "tests\CreativeCoders.GitTool.GitLab.UnitTests\CreativeCoders.GitTool.GitLab.UnitTests.csproj", "{40CB3BB2-1AD4-4008-8D61-C179342F07F2}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CreativeCoders.GitTool.Commands.Releases", "source\GitTool\Commands\CreativeCoders.GitTool.Commands.Releases\CreativeCoders.GitTool.Commands.Releases.csproj", "{9F00E2AF-FA50-49DD-B6B0-3330E2883044}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CreativeCoders.GitTool.Commands.Tool", "source\GitTool\Commands\CreativeCoders.GitTool.Commands.Tool\CreativeCoders.GitTool.Commands.Tool.csproj", "{E0E53B66-17F8-4A01-A799-8998FD0A20ED}" -EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "build", "build", "{E4F28808-C129-4AE9-8454-08EAB02D7E7F}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CreativeCoders.GitTool.Commands.Shared", "source\GitTool\Commands\CreativeCoders.GitTool.Commands.Shared\CreativeCoders.GitTool.Commands.Shared.csproj", "{FC8C53FC-85DB-4A43-9D80-CEFF9047250E}" -EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "__global", "__global", "{957CFE00-6B57-4EBF-BEE2-319A5C7B9EF9}" ProjectSection(SolutionItems) = preProject .gitattributes = .gitattributes @@ -88,6 +74,12 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "build", "build", "{DE982092 build.sh = build.sh EndProjectSection EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Cli", "Cli", "{D65676E3-6820-464B-8493-597E3E1DCD98}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CreativeCoders.GitTool.Cli.GtApp", "source\GitTool\CreativeCoders.GitTool.Cli.GtApp\CreativeCoders.GitTool.Cli.GtApp.csproj", "{46156AAB-B9F6-4C99-AD0A-9F370DB87679}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CreativeCoders.GitTool.Cli.Commands", "source\GitTool\CreativeCoders.GitTool.Cli.Commands\CreativeCoders.GitTool.Cli.Commands.csproj", "{80C7112B-7D72-4585-BDFA-101289319B2C}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -118,18 +110,6 @@ Global {F79BE247-8C60-4A51-B538-B2387C2D357F}.Debug|Any CPU.Build.0 = Debug|Any CPU {F79BE247-8C60-4A51-B538-B2387C2D357F}.Release|Any CPU.ActiveCfg = Release|Any CPU {F79BE247-8C60-4A51-B538-B2387C2D357F}.Release|Any CPU.Build.0 = Release|Any CPU - {1589F267-9A07-470B-A13C-9FE1CE5016B5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {1589F267-9A07-470B-A13C-9FE1CE5016B5}.Debug|Any CPU.Build.0 = Debug|Any CPU - {1589F267-9A07-470B-A13C-9FE1CE5016B5}.Release|Any CPU.ActiveCfg = Release|Any CPU - {1589F267-9A07-470B-A13C-9FE1CE5016B5}.Release|Any CPU.Build.0 = Release|Any CPU - {0B7EBFC9-9D04-4F2C-8B63-387F2A2AAAD9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {0B7EBFC9-9D04-4F2C-8B63-387F2A2AAAD9}.Debug|Any CPU.Build.0 = Debug|Any CPU - {0B7EBFC9-9D04-4F2C-8B63-387F2A2AAAD9}.Release|Any CPU.ActiveCfg = Release|Any CPU - {0B7EBFC9-9D04-4F2C-8B63-387F2A2AAAD9}.Release|Any CPU.Build.0 = Release|Any CPU - {35C347B1-6DA0-4D9F-8259-928C561EEF8C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {35C347B1-6DA0-4D9F-8259-928C561EEF8C}.Debug|Any CPU.Build.0 = Debug|Any CPU - {35C347B1-6DA0-4D9F-8259-928C561EEF8C}.Release|Any CPU.ActiveCfg = Release|Any CPU - {35C347B1-6DA0-4D9F-8259-928C561EEF8C}.Release|Any CPU.Build.0 = Release|Any CPU {0E6E1AE1-7176-4D40-96AE-7A9FDC4D3223}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {0E6E1AE1-7176-4D40-96AE-7A9FDC4D3223}.Debug|Any CPU.Build.0 = Debug|Any CPU {0E6E1AE1-7176-4D40-96AE-7A9FDC4D3223}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -146,20 +126,16 @@ Global {40CB3BB2-1AD4-4008-8D61-C179342F07F2}.Debug|Any CPU.Build.0 = Debug|Any CPU {40CB3BB2-1AD4-4008-8D61-C179342F07F2}.Release|Any CPU.ActiveCfg = Release|Any CPU {40CB3BB2-1AD4-4008-8D61-C179342F07F2}.Release|Any CPU.Build.0 = Release|Any CPU - {9F00E2AF-FA50-49DD-B6B0-3330E2883044}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {9F00E2AF-FA50-49DD-B6B0-3330E2883044}.Debug|Any CPU.Build.0 = Debug|Any CPU - {9F00E2AF-FA50-49DD-B6B0-3330E2883044}.Release|Any CPU.ActiveCfg = Release|Any CPU - {9F00E2AF-FA50-49DD-B6B0-3330E2883044}.Release|Any CPU.Build.0 = Release|Any CPU - {E0E53B66-17F8-4A01-A799-8998FD0A20ED}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {E0E53B66-17F8-4A01-A799-8998FD0A20ED}.Debug|Any CPU.Build.0 = Debug|Any CPU - {E0E53B66-17F8-4A01-A799-8998FD0A20ED}.Release|Any CPU.ActiveCfg = Release|Any CPU - {E0E53B66-17F8-4A01-A799-8998FD0A20ED}.Release|Any CPU.Build.0 = Release|Any CPU - {FC8C53FC-85DB-4A43-9D80-CEFF9047250E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {FC8C53FC-85DB-4A43-9D80-CEFF9047250E}.Debug|Any CPU.Build.0 = Debug|Any CPU - {FC8C53FC-85DB-4A43-9D80-CEFF9047250E}.Release|Any CPU.ActiveCfg = Release|Any CPU - {FC8C53FC-85DB-4A43-9D80-CEFF9047250E}.Release|Any CPU.Build.0 = Release|Any CPU {06510226-737C-4300-92A5-3FE3C5E4D6A4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {06510226-737C-4300-92A5-3FE3C5E4D6A4}.Release|Any CPU.ActiveCfg = Release|Any CPU + {46156AAB-B9F6-4C99-AD0A-9F370DB87679}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {46156AAB-B9F6-4C99-AD0A-9F370DB87679}.Debug|Any CPU.Build.0 = Debug|Any CPU + {46156AAB-B9F6-4C99-AD0A-9F370DB87679}.Release|Any CPU.ActiveCfg = Release|Any CPU + {46156AAB-B9F6-4C99-AD0A-9F370DB87679}.Release|Any CPU.Build.0 = Release|Any CPU + {80C7112B-7D72-4585-BDFA-101289319B2C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {80C7112B-7D72-4585-BDFA-101289319B2C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {80C7112B-7D72-4585-BDFA-101289319B2C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {80C7112B-7D72-4585-BDFA-101289319B2C}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -167,26 +143,22 @@ Global GlobalSection(NestedProjects) = preSolution {90C87656-57A8-4AE9-8619-DA08AA137D6A} = {35D676C5-4FB7-41AB-A60B-DD8F30ACFB5B} {EA56F26E-54C0-4C1C-986C-2785829AE2D8} = {35D676C5-4FB7-41AB-A60B-DD8F30ACFB5B} - {4AD18751-E2F6-40F3-99F6-69FA2320CA30} = {90C87656-57A8-4AE9-8619-DA08AA137D6A} {AD6C98CD-A96D-4795-B9A7-F321D6597C11} = {EA56F26E-54C0-4C1C-986C-2785829AE2D8} {0858E655-2326-48F6-85FA-01E068A0331F} = {EA56F26E-54C0-4C1C-986C-2785829AE2D8} {25BCE0B9-068F-4EC0-BCD0-680B3FE47626} = {EA56F26E-54C0-4C1C-986C-2785829AE2D8} {CF40538D-E176-4449-B27F-22BB43E5BFD6} = {90C87656-57A8-4AE9-8619-DA08AA137D6A} {8B3F3455-5D00-47A3-B40E-F3E3E3C5E5DA} = {90C87656-57A8-4AE9-8619-DA08AA137D6A} {F79BE247-8C60-4A51-B538-B2387C2D357F} = {90C87656-57A8-4AE9-8619-DA08AA137D6A} - {1589F267-9A07-470B-A13C-9FE1CE5016B5} = {4AD18751-E2F6-40F3-99F6-69FA2320CA30} - {0B7EBFC9-9D04-4F2C-8B63-387F2A2AAAD9} = {4AD18751-E2F6-40F3-99F6-69FA2320CA30} - {35C347B1-6DA0-4D9F-8259-928C561EEF8C} = {90C87656-57A8-4AE9-8619-DA08AA137D6A} {0E6E1AE1-7176-4D40-96AE-7A9FDC4D3223} = {B7558045-D005-49D4-9205-55A32B6C99DE} {8E5F6024-5850-4272-9A9D-45CF566C526A} = {B7558045-D005-49D4-9205-55A32B6C99DE} {B6FE210C-94B0-4D65-A881-42FA3F3A9856} = {B7558045-D005-49D4-9205-55A32B6C99DE} {40CB3BB2-1AD4-4008-8D61-C179342F07F2} = {B7558045-D005-49D4-9205-55A32B6C99DE} - {9F00E2AF-FA50-49DD-B6B0-3330E2883044} = {4AD18751-E2F6-40F3-99F6-69FA2320CA30} - {E0E53B66-17F8-4A01-A799-8998FD0A20ED} = {4AD18751-E2F6-40F3-99F6-69FA2320CA30} - {FC8C53FC-85DB-4A43-9D80-CEFF9047250E} = {4AD18751-E2F6-40F3-99F6-69FA2320CA30} {06510226-737C-4300-92A5-3FE3C5E4D6A4} = {E4F28808-C129-4AE9-8454-08EAB02D7E7F} {E91F4387-0278-43C4-AE97-E9C54E414C41} = {957CFE00-6B57-4EBF-BEE2-319A5C7B9EF9} {DE982092-6508-4062-99D5-6A6EE9ECB81F} = {957CFE00-6B57-4EBF-BEE2-319A5C7B9EF9} + {D65676E3-6820-464B-8493-597E3E1DCD98} = {90C87656-57A8-4AE9-8619-DA08AA137D6A} + {46156AAB-B9F6-4C99-AD0A-9F370DB87679} = {D65676E3-6820-464B-8493-597E3E1DCD98} + {80C7112B-7D72-4585-BDFA-101289319B2C} = {D65676E3-6820-464B-8493-597E3E1DCD98} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {D38E5978-8FB3-474B-BDCB-18853E21A429} diff --git a/build/Build.csproj b/build/Build.csproj index fc602e8..3c06322 100644 --- a/build/Build.csproj +++ b/build/Build.csproj @@ -8,7 +8,7 @@ - + diff --git a/build/BuildContext.cs b/build/BuildContext.cs index 07eb0f0..71ebe00 100644 --- a/build/BuildContext.cs +++ b/build/BuildContext.cs @@ -35,9 +35,9 @@ public class BuildContext(ICakeContext context) public DirectoryPath PublishOutputDir => ArtifactsDir.Combine("published"); - private const string CliPath = "source/GitTool/CreativeCoders.GitTool.Cli"; + private const string CliPath = "source/GitTool/CreativeCoders.GitTool.Cli.GtApp"; - private const string CliProjectFile = "CreativeCoders.GitTool.Cli.csproj"; + private const string CliProjectFile = "CreativeCoders.GitTool.Cli.GtApp.csproj"; public IEnumerable PublishingItems => [ diff --git a/source/Git/CreativeCoders.Git.Abstractions/CreativeCoders.Git.Abstractions.csproj b/source/Git/CreativeCoders.Git.Abstractions/CreativeCoders.Git.Abstractions.csproj index 1576e74..141d0a5 100644 --- a/source/Git/CreativeCoders.Git.Abstractions/CreativeCoders.Git.Abstractions.csproj +++ b/source/Git/CreativeCoders.Git.Abstractions/CreativeCoders.Git.Abstractions.csproj @@ -5,8 +5,8 @@ - - + + diff --git a/source/Git/CreativeCoders.Git.Abstractions/IGitRepositoryFactory.cs b/source/Git/CreativeCoders.Git.Abstractions/IGitRepositoryFactory.cs index fc8039e..5d3c94a 100644 --- a/source/Git/CreativeCoders.Git.Abstractions/IGitRepositoryFactory.cs +++ b/source/Git/CreativeCoders.Git.Abstractions/IGitRepositoryFactory.cs @@ -8,4 +8,4 @@ public interface IGitRepositoryFactory IGitRepository OpenRepository(string? path); IGitRepository OpenRepositoryFromCurrentDir(); -} \ No newline at end of file +} diff --git a/source/Git/CreativeCoders.Git/CreativeCoders.Git.csproj b/source/Git/CreativeCoders.Git/CreativeCoders.Git.csproj index c2d4292..635c87d 100644 --- a/source/Git/CreativeCoders.Git/CreativeCoders.Git.csproj +++ b/source/Git/CreativeCoders.Git/CreativeCoders.Git.csproj @@ -5,9 +5,9 @@ - - - + + + diff --git a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Branches/BranchesController.cs b/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Branches/BranchesController.cs deleted file mode 100644 index 8b2101b..0000000 --- a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Branches/BranchesController.cs +++ /dev/null @@ -1,50 +0,0 @@ -using System.Threading.Tasks; -using CreativeCoders.Core; -using CreativeCoders.GitTool.Commands.Branches.Commands.Info; -using CreativeCoders.GitTool.Commands.Branches.Commands.List; -using CreativeCoders.GitTool.Commands.Branches.Commands.Pull; -using CreativeCoders.GitTool.Commands.Branches.Commands.Push; -using CreativeCoders.GitTool.Commands.Branches.Commands.Update; -using CreativeCoders.GitTool.Commands.Shared.CommandExecuting; -using CreativeCoders.SysConsole.Cli.Actions; -using CreativeCoders.SysConsole.Cli.Actions.Definition; -using JetBrains.Annotations; - -namespace CreativeCoders.GitTool.Commands.Branches; - -[CliController("branch")] -public class BranchesController -{ - private readonly IGitToolCommandExecutor _commandExecutor; - - public BranchesController(IGitToolCommandExecutor commandExecutor) - { - _commandExecutor = Ensure.NotNull(commandExecutor, nameof(commandExecutor)); - } - - [UsedImplicitly] - [CliAction] - [CliAction("list", HelpText = "List repository branches")] - public async Task ListAsync(ListBranchesOptions options) - => new(await _commandExecutor.ExecuteAsync(options)); - - [UsedImplicitly] - [CliAction("update", HelpText = "Update all permanent local branches by pulling from remote branches")] - public async Task UpdateAsync(UpdateBranchesOptions options) - => new(await _commandExecutor.ExecuteAsync(options)); - - [UsedImplicitly] - [CliAction("info", HelpText = "Show infos of current branch")] - public async Task InfoAsync(InfoBranchesOptions options) - => new(await _commandExecutor.ExecuteAsync(options)); - - [UsedImplicitly] - [CliAction("pull", HelpText = "Pulls updates for current branch from remote")] - public async Task PullAsync(PullBranchOptions options) - => new(await _commandExecutor.ExecuteAsync(options)); - - [UsedImplicitly] - [CliAction("push", HelpText = "Pushes updates from current branch to remote")] - public async Task PushAsync(PushBranchOptions options) - => new(await _commandExecutor.ExecuteAsync(options)); -} \ No newline at end of file diff --git a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Branches/Commands/List/BranchLocation.cs b/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Branches/Commands/List/BranchLocation.cs deleted file mode 100644 index b69831b..0000000 --- a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Branches/Commands/List/BranchLocation.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace CreativeCoders.GitTool.Commands.Branches.Commands.List; - -public enum BranchLocation -{ - All, - Local, - Remote -} \ No newline at end of file diff --git a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Branches/Commands/Pull/PullBranchCommand.cs b/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Branches/Commands/Pull/PullBranchCommand.cs deleted file mode 100644 index b4c51ae..0000000 --- a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Branches/Commands/Pull/PullBranchCommand.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System.Threading.Tasks; -using CreativeCoders.Core; -using CreativeCoders.Git.Abstractions; -using CreativeCoders.GitTool.Commands.Shared; -using CreativeCoders.GitTool.Commands.Shared.CommandExecuting; -using JetBrains.Annotations; - -namespace CreativeCoders.GitTool.Commands.Branches.Commands.Pull; - -[UsedImplicitly] -public class PullBranchCommand : IGitToolCommandWithOptions -{ - private readonly IGitToolPullCommand _pullCommand; - - public PullBranchCommand(IGitToolPullCommand pullCommand) - { - _pullCommand = Ensure.NotNull(pullCommand); - } - - public async Task ExecuteAsync(IGitRepository gitRepository, PullBranchOptions options) - { - return await _pullCommand.ExecuteAsync(gitRepository, options.Verbose).ConfigureAwait(false); - } -} diff --git a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Branches/Commands/Pull/PullBranchOptions.cs b/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Branches/Commands/Pull/PullBranchOptions.cs deleted file mode 100644 index 05a0402..0000000 --- a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Branches/Commands/Pull/PullBranchOptions.cs +++ /dev/null @@ -1,11 +0,0 @@ -using CreativeCoders.SysConsole.Cli.Parsing; -using JetBrains.Annotations; - -namespace CreativeCoders.GitTool.Commands.Branches.Commands.Pull; - -[PublicAPI] -public class PullBranchOptions -{ - [OptionParameter('v', "verbose")] - public bool Verbose { get; set; } -} diff --git a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Branches/Commands/Push/PushBranchCommand.cs b/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Branches/Commands/Push/PushBranchCommand.cs deleted file mode 100644 index 0f4afaf..0000000 --- a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Branches/Commands/Push/PushBranchCommand.cs +++ /dev/null @@ -1,26 +0,0 @@ -using System.Threading.Tasks; -using CreativeCoders.Core; -using CreativeCoders.Git.Abstractions; -using CreativeCoders.GitTool.Commands.Shared; -using CreativeCoders.GitTool.Commands.Shared.CommandExecuting; -using JetBrains.Annotations; - -namespace CreativeCoders.GitTool.Commands.Branches.Commands.Push; - -[UsedImplicitly] -public class PushBranchCommand : IGitToolCommandWithOptions -{ - private readonly IGitToolPushCommand _pushCommand; - - public PushBranchCommand(IGitToolPushCommand pushCommand) - { - _pushCommand = Ensure.NotNull(pushCommand); - } - - public async Task ExecuteAsync(IGitRepository gitRepository, PushBranchOptions options) - { - return await _pushCommand - .ExecuteAsync(gitRepository, options.CreateRemoteBranchIfNotExists, options.ConfirmPush, options.Verbose) - .ConfigureAwait(false); - } -} diff --git a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Branches/CreativeCoders.GitTool.Commands.Branches.csproj b/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Branches/CreativeCoders.GitTool.Commands.Branches.csproj deleted file mode 100644 index f751023..0000000 --- a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Branches/CreativeCoders.GitTool.Commands.Branches.csproj +++ /dev/null @@ -1,26 +0,0 @@ - - - - enable - - - - - - - - - - - - - - - - - - - - - - diff --git a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Features/Commands/FinishFeature/FinishFeatureCommand.cs b/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Features/Commands/FinishFeature/FinishFeatureCommand.cs deleted file mode 100644 index 8ae55cd..0000000 --- a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Features/Commands/FinishFeature/FinishFeatureCommand.cs +++ /dev/null @@ -1,54 +0,0 @@ -using System.Threading.Tasks; -using CreativeCoders.Core; -using CreativeCoders.Git.Abstractions; -using CreativeCoders.GitTool.Base; -using CreativeCoders.GitTool.Base.Configurations; -using CreativeCoders.GitTool.Commands.Shared.CommandExecuting; -using JetBrains.Annotations; - -namespace CreativeCoders.GitTool.Commands.Features.Commands.FinishFeature; - -[UsedImplicitly] -public class FinishFeatureCommand : IGitToolCommandWithOptions -{ - private readonly IFinishFeatureSteps _finishFeatureSteps; - - private readonly IRepositoryConfigurations _repositoryConfigurations; - - public FinishFeatureCommand(IRepositoryConfigurations repositoryConfigurations, - IFinishFeatureSteps finishFeatureSteps) - { - _repositoryConfigurations = Ensure.NotNull(repositoryConfigurations); - _finishFeatureSteps = Ensure.NotNull(finishFeatureSteps); - } - - private FinishFeatureData CreateData(IGitRepository gitRepository, FinishFeatureOptions options) - { - var configuration = _repositoryConfigurations.GetConfiguration(gitRepository); - - return new FinishFeatureData(gitRepository, configuration.GetFeatureBranchName(options.FeatureName), - configuration.GetDefaultBranchName(gitRepository.Info.MainBranch), configuration.GitServiceProviderName, - options.PullRequestTitle); - } - - public async Task ExecuteAsync(IGitRepository gitRepository, FinishFeatureOptions options) - { - var data = CreateData(gitRepository, options); - - _finishFeatureSteps.UpdateFeatureBranch(data); - - _finishFeatureSteps.MergeDefaultBranch(data); - - await _finishFeatureSteps.PushFeatureBranch(data).ConfigureAwait(false); - - // Ensure remote branch creation and use it for pull request - - await _finishFeatureSteps.CreatePullRequest(data).ConfigureAwait(false); - - gitRepository.Branches.CheckOut(data.DefaultBranch); - - gitRepository.Branches.DeleteLocalBranch(data.FeatureBranch); - - return ReturnCodes.Success; - } -} diff --git a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Features/Commands/StartFeature/StartFeatureData.cs b/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Features/Commands/StartFeature/StartFeatureData.cs deleted file mode 100644 index 1aa11e6..0000000 --- a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Features/Commands/StartFeature/StartFeatureData.cs +++ /dev/null @@ -1,19 +0,0 @@ -using CreativeCoders.Git.Abstractions; - -namespace CreativeCoders.GitTool.Commands.Features.Commands.StartFeature; - -public class StartFeatureData -{ - public StartFeatureData(IGitRepository gitRepository, string featureBranch, string defaultBranch) - { - GitRepository = gitRepository; - FeatureBranch = featureBranch; - DefaultBranch = defaultBranch; - } - - public IGitRepository GitRepository { get; } - - public string FeatureBranch { get; } - - public string DefaultBranch { get; } -} \ No newline at end of file diff --git a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Features/CreativeCoders.GitTool.Commands.Features.csproj b/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Features/CreativeCoders.GitTool.Commands.Features.csproj deleted file mode 100644 index 44723ad..0000000 --- a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Features/CreativeCoders.GitTool.Commands.Features.csproj +++ /dev/null @@ -1,19 +0,0 @@ - - - - enable - - - - - - - - - - - - - - - diff --git a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Features/FeaturesController.cs b/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Features/FeaturesController.cs deleted file mode 100644 index dd475b1..0000000 --- a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Features/FeaturesController.cs +++ /dev/null @@ -1,31 +0,0 @@ -using System.Threading.Tasks; -using CreativeCoders.Core; -using CreativeCoders.GitTool.Commands.Features.Commands.FinishFeature; -using CreativeCoders.GitTool.Commands.Features.Commands.StartFeature; -using CreativeCoders.GitTool.Commands.Shared.CommandExecuting; -using CreativeCoders.SysConsole.Cli.Actions; -using CreativeCoders.SysConsole.Cli.Actions.Definition; -using JetBrains.Annotations; - -namespace CreativeCoders.GitTool.Commands.Features; - -[CliController("feature")] -public class FeaturesController -{ - private readonly IGitToolCommandExecutor _commandExecutor; - - public FeaturesController(IGitToolCommandExecutor commandExecutor) - { - _commandExecutor = Ensure.NotNull(commandExecutor, nameof(commandExecutor)); - } - - [UsedImplicitly] - [CliAction("start", HelpText = "Start a new feature")] - public async Task StartAsync(StartFeatureOptions options) - => new(await _commandExecutor.ExecuteAsync(options)); - - [UsedImplicitly] - [CliAction("finish", HelpText = "Finish an active feature")] - public async Task FinishAsync(FinishFeatureOptions options) - => new(await _commandExecutor.ExecuteAsync(options)); -} \ No newline at end of file diff --git a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Releases/CreativeCoders.GitTool.Commands.Releases.csproj b/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Releases/CreativeCoders.GitTool.Commands.Releases.csproj deleted file mode 100644 index b7a1c9e..0000000 --- a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Releases/CreativeCoders.GitTool.Commands.Releases.csproj +++ /dev/null @@ -1,17 +0,0 @@ - - - - enable - - - - - - - - - - - - - diff --git a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Releases/ReleasesController.cs b/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Releases/ReleasesController.cs deleted file mode 100644 index e8b230c..0000000 --- a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Releases/ReleasesController.cs +++ /dev/null @@ -1,25 +0,0 @@ -using System.Threading.Tasks; -using CreativeCoders.Core; -using CreativeCoders.GitTool.Commands.Releases.Commands.Create; -using CreativeCoders.GitTool.Commands.Shared.CommandExecuting; -using CreativeCoders.SysConsole.Cli.Actions; -using CreativeCoders.SysConsole.Cli.Actions.Definition; -using JetBrains.Annotations; - -namespace CreativeCoders.GitTool.Commands.Releases; - -[PublicAPI] -[CliController("release")] -public class ReleasesController -{ - private readonly IGitToolCommandExecutor _commandExecutor; - - public ReleasesController(IGitToolCommandExecutor commandExecutor) - { - _commandExecutor = Ensure.NotNull(commandExecutor, nameof(commandExecutor)); - } - - [CliAction("create")] - public async Task CreateAsync(CreateReleaseOptions options) - => new(await _commandExecutor.ExecuteAsync(options)); -} \ No newline at end of file diff --git a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Shared/CommandExecuting/GitToolCommandExecutor.cs b/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Shared/CommandExecuting/GitToolCommandExecutor.cs deleted file mode 100644 index 0414400..0000000 --- a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Shared/CommandExecuting/GitToolCommandExecutor.cs +++ /dev/null @@ -1,75 +0,0 @@ -using CreativeCoders.Core; -using CreativeCoders.Core.Reflection; -using CreativeCoders.Git.Abstractions; -using CreativeCoders.GitTool.Base.Configurations; - -namespace CreativeCoders.GitTool.Commands.Shared.CommandExecuting; - -public class GitToolCommandExecutor : IGitToolCommandExecutor -{ - private readonly IGitRepositoryFactory _gitRepositoryFactory; - - private readonly IRepositoryConfigurations _repositoryConfigurations; - - private readonly IServiceProvider _serviceProvider; - - public GitToolCommandExecutor(IServiceProvider serviceProvider, IGitRepositoryFactory gitRepositoryFactory, - IRepositoryConfigurations repositoryConfigurations) - { - _serviceProvider = Ensure.NotNull(serviceProvider); - _gitRepositoryFactory = Ensure.NotNull(gitRepositoryFactory); - _repositoryConfigurations = Ensure.NotNull(repositoryConfigurations); - } - - public async Task ExecuteAsync() - where TCommand : IGitToolCommand - { - var command = typeof(TCommand).CreateInstance(_serviceProvider); - - if (command == null) - { - throw new InvalidOperationException("Command object cannot be created"); - } - - using var gitRepository = _gitRepositoryFactory.OpenRepositoryFromCurrentDir(); - - var configuration = _repositoryConfigurations.GetConfiguration(gitRepository); - - if (configuration.DisableCertificateValidation) - { - gitRepository.CertificateCheck = (_, args) => - { - args.IsValid = true; - return true; - }; - } - - return await command.ExecuteAsync(gitRepository).ConfigureAwait(false); - } - - public async Task ExecuteAsync(TCommandOptions options) - where TCommand : IGitToolCommandWithOptions - { - var command = typeof(TCommand).CreateInstance>(_serviceProvider); - - if (command == null) - { - throw new InvalidOperationException("Command object cannot be created"); - } - - using var gitRepository = _gitRepositoryFactory.OpenRepositoryFromCurrentDir(); - - var configuration = _repositoryConfigurations.GetConfiguration(gitRepository); - - if (configuration.DisableCertificateValidation) - { - gitRepository.CertificateCheck = (_, args) => - { - args.IsValid = true; - return true; - }; - } - - return await command.ExecuteAsync(gitRepository, options).ConfigureAwait(false); - } -} diff --git a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Shared/CommandExecuting/IGitToolCommand.cs b/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Shared/CommandExecuting/IGitToolCommand.cs deleted file mode 100644 index cd6cbf7..0000000 --- a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Shared/CommandExecuting/IGitToolCommand.cs +++ /dev/null @@ -1,8 +0,0 @@ -using CreativeCoders.Git.Abstractions; - -namespace CreativeCoders.GitTool.Commands.Shared.CommandExecuting; - -public interface IGitToolCommand -{ - Task ExecuteAsync(IGitRepository gitRepository); -} diff --git a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Shared/CommandExecuting/IGitToolCommandExecutor.cs b/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Shared/CommandExecuting/IGitToolCommandExecutor.cs deleted file mode 100644 index e9898e8..0000000 --- a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Shared/CommandExecuting/IGitToolCommandExecutor.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace CreativeCoders.GitTool.Commands.Shared.CommandExecuting; - -public interface IGitToolCommandExecutor -{ - Task ExecuteAsync() - where TCommand : IGitToolCommand; - - Task ExecuteAsync(TCommandOptions options) - where TCommand : IGitToolCommandWithOptions; -} diff --git a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Shared/CommandExecuting/IGitToolCommandWithOptions.cs b/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Shared/CommandExecuting/IGitToolCommandWithOptions.cs deleted file mode 100644 index be9e584..0000000 --- a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Shared/CommandExecuting/IGitToolCommandWithOptions.cs +++ /dev/null @@ -1,8 +0,0 @@ -using CreativeCoders.Git.Abstractions; - -namespace CreativeCoders.GitTool.Commands.Shared.CommandExecuting; - -public interface IGitToolCommandWithOptions -{ - Task ExecuteAsync(IGitRepository gitRepository, TOptions options); -} diff --git a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Shared/CreativeCoders.GitTool.Commands.Shared.csproj b/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Shared/CreativeCoders.GitTool.Commands.Shared.csproj deleted file mode 100644 index 57dfe28..0000000 --- a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Shared/CreativeCoders.GitTool.Commands.Shared.csproj +++ /dev/null @@ -1,17 +0,0 @@ - - - - enable - enable - - - - - - - - - - - - diff --git a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Tool/CreativeCoders.GitTool.Commands.Tool.csproj b/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Tool/CreativeCoders.GitTool.Commands.Tool.csproj deleted file mode 100644 index 13b2926..0000000 --- a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Tool/CreativeCoders.GitTool.Commands.Tool.csproj +++ /dev/null @@ -1,15 +0,0 @@ - - - - enable - - - - - - - - - - - diff --git a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Tool/ToolController.cs b/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Tool/ToolController.cs deleted file mode 100644 index cb89694..0000000 --- a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Tool/ToolController.cs +++ /dev/null @@ -1,98 +0,0 @@ -using System.Threading.Tasks; -using CreativeCoders.Core; -using CreativeCoders.Core.SysEnvironment; -using CreativeCoders.Git.Abstractions; -using CreativeCoders.GitTool.Base; -using CreativeCoders.GitTool.Base.Configurations; -using CreativeCoders.SysConsole.Cli.Actions.Definition; -using CreativeCoders.SysConsole.Core; -using JetBrains.Annotations; -using Spectre.Console; - -namespace CreativeCoders.GitTool.Commands.Tool; - -[PublicAPI] -[CliController] -public class ToolController -{ - private readonly IAnsiConsole _console; - - private readonly IGitRepositoryFactory _gitRepositoryFactory; - - private readonly IGitServiceProviders _gitServiceProviders; - - private readonly IRepositoryConfigurations _repositoryConfigurations; - - public ToolController(IAnsiConsole console, IRepositoryConfigurations repositoryConfigurations, - IGitRepositoryFactory gitRepositoryFactory, IGitServiceProviders gitServiceProviders) - { - _console = Ensure.NotNull(console); - _gitServiceProviders = Ensure.NotNull(gitServiceProviders); - _gitRepositoryFactory = Ensure.NotNull(gitRepositoryFactory); - _repositoryConfigurations = Ensure.NotNull(repositoryConfigurations); - } - - [CliAction("setup")] - public async Task Setup() - { - using var repository = _gitRepositoryFactory.OpenRepositoryFromCurrentDir(); - - var configuration = _repositoryConfigurations.GetConfiguration(repository); - - _console.PrintBlock() - .WriteLine() - .WriteLine("Development branch (empty = no development branch)"); - - var developBranch = - _console.Prompt(new TextPrompt($"(Current value = '{configuration.DevelopBranch}'): ") - { AllowEmpty = true }); - - configuration.DevelopBranch = developBranch ?? string.Empty; - configuration.HasDevelopBranch = !string.IsNullOrEmpty(developBranch); - - var featureBranchPrefix = _console.Prompt(new TextPrompt( - $"Prefix for feature branches (Empty = current value '{configuration.FeatureBranchPrefix}'): ") - { AllowEmpty = true }); - - if (!string.IsNullOrEmpty(featureBranchPrefix)) - { - configuration.FeatureBranchPrefix = featureBranchPrefix; - } - - var selectionPrompt = new SelectionPrompt(); - - var gitProviderName = _console.Prompt(selectionPrompt.AddChoices(_gitServiceProviders.ProviderNames)); - - if (!string.IsNullOrEmpty(gitProviderName)) - { - configuration.GitServiceProviderName = gitProviderName; - } - - var disableCertValidationPrompt = new ConfirmationPrompt("Disable certificate check (true/false): ") - { DefaultValue = configuration.DisableCertificateValidation }; - - configuration.DisableCertificateValidation = _console.Prompt(disableCertValidationPrompt); - - await _repositoryConfigurations.SaveConfigurationAsync(repository.Info.RemoteUri, configuration); - } - - // ReSharper disable once StringLiteralTypo - [CliAction("showconfig")] - public void ShowConfig() - { - using var repository = _gitRepositoryFactory.OpenRepository(Env.CurrentDirectory); - - var configuration = _repositoryConfigurations.GetConfiguration(repository); - - _console.PrintBlock() - .WriteLine() - .WriteLine($"Configuration for '{repository.Info.RemoteUri}'") - .WriteLine() - .WriteLine($"HasDevelopBranch: {configuration.HasDevelopBranch}") - .WriteLine($"DevelopBranch: {configuration.DevelopBranch}") - .WriteLine($"FeatureBranchPrefix: {configuration.FeatureBranchPrefix}") - .WriteLine($"GitServiceProviderName: {configuration.GitServiceProviderName}") - .WriteLine($"DisableCertificateValidation: {configuration.DisableCertificateValidation}") - .WriteLine(); - } -} diff --git a/source/GitTool/CreativeCoders.GitTool.Base/CreativeCoders.GitTool.Base.csproj b/source/GitTool/CreativeCoders.GitTool.Base/CreativeCoders.GitTool.Base.csproj index f8a0507..870de7a 100644 --- a/source/GitTool/CreativeCoders.GitTool.Base/CreativeCoders.GitTool.Base.csproj +++ b/source/GitTool/CreativeCoders.GitTool.Base/CreativeCoders.GitTool.Base.csproj @@ -5,10 +5,10 @@ - - - - + + + + diff --git a/source/GitTool/CreativeCoders.GitTool.Cli.Commands/BranchGroup/BranchCommandGroup.cs b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/BranchGroup/BranchCommandGroup.cs new file mode 100644 index 0000000..d4f9283 --- /dev/null +++ b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/BranchGroup/BranchCommandGroup.cs @@ -0,0 +1,10 @@ +using CreativeCoders.Cli.Core; + +[assembly: CliCommandGroup(["branch"], "Commands for branches")] + +namespace CreativeCoders.GitTool.Cli.Commands.BranchGroup; + +public static class BranchCommandGroup +{ + public const string Name = "branch"; +} diff --git a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Branches/Commands/Info/InfoBranchesCommand.cs b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/BranchGroup/Info/InfoBranchesCommand.cs similarity index 63% rename from source/GitTool/Commands/CreativeCoders.GitTool.Commands.Branches/Commands/Info/InfoBranchesCommand.cs rename to source/GitTool/CreativeCoders.GitTool.Cli.Commands/BranchGroup/Info/InfoBranchesCommand.cs index d093c66..ba7adec 100644 --- a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Branches/Commands/Info/InfoBranchesCommand.cs +++ b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/BranchGroup/Info/InfoBranchesCommand.cs @@ -1,25 +1,20 @@ -using System.Linq; -using System.Threading.Tasks; +using CreativeCoders.Cli.Core; using CreativeCoders.Core; using CreativeCoders.Git.Abstractions; -using CreativeCoders.GitTool.Commands.Shared; -using CreativeCoders.GitTool.Commands.Shared.CommandExecuting; +using CreativeCoders.GitTool.Cli.Commands.Shared; using JetBrains.Annotations; using Spectre.Console; -namespace CreativeCoders.GitTool.Commands.Branches.Commands.Info; +namespace CreativeCoders.GitTool.Cli.Commands.BranchGroup.Info; [UsedImplicitly] -public class InfoBranchesCommand : IGitToolCommandWithOptions +[CliCommand([BranchCommandGroup.Name, "info"], Description = "Shows information about the current branch")] +public class InfoBranchesCommand(IAnsiConsole ansiConsole, IGitRepository gitRepository) + : ICliCommand { - private readonly IAnsiConsole _ansiConsole; + private readonly IAnsiConsole _ansiConsole = Ensure.NotNull(ansiConsole); - public InfoBranchesCommand(IAnsiConsole ansiConsole) - { - _ansiConsole = Ensure.NotNull(ansiConsole); - } - - public Task ExecuteAsync(IGitRepository gitRepository, InfoBranchesOptions options) + public Task ExecuteAsync(InfoBranchesOptions options) { _ansiConsole.WriteLine("Branch info"); _ansiConsole.WriteLine(); @@ -51,6 +46,6 @@ public Task ExecuteAsync(IGitRepository gitRepository, InfoBranchesOptions _ansiConsole.WriteLine(); - return Task.FromResult(0); + return Task.FromResult(CommandResult.Success); } } diff --git a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Branches/Commands/Info/InfoBranchesOptions.cs b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/BranchGroup/Info/InfoBranchesOptions.cs similarity index 80% rename from source/GitTool/Commands/CreativeCoders.GitTool.Commands.Branches/Commands/Info/InfoBranchesOptions.cs rename to source/GitTool/CreativeCoders.GitTool.Cli.Commands/BranchGroup/Info/InfoBranchesOptions.cs index 6d30424..9ea9a4b 100644 --- a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Branches/Commands/Info/InfoBranchesOptions.cs +++ b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/BranchGroup/Info/InfoBranchesOptions.cs @@ -1,7 +1,7 @@ using CreativeCoders.SysConsole.Cli.Parsing; using JetBrains.Annotations; -namespace CreativeCoders.GitTool.Commands.Branches.Commands.Info; +namespace CreativeCoders.GitTool.Cli.Commands.BranchGroup.Info; [PublicAPI] public class InfoBranchesOptions diff --git a/source/GitTool/CreativeCoders.GitTool.Cli.Commands/BranchGroup/List/BranchLocation.cs b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/BranchGroup/List/BranchLocation.cs new file mode 100644 index 0000000..722f78d --- /dev/null +++ b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/BranchGroup/List/BranchLocation.cs @@ -0,0 +1,8 @@ +namespace CreativeCoders.GitTool.Cli.Commands.BranchGroup.List; + +public enum BranchLocation +{ + All, + Local, + Remote +} diff --git a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Branches/Commands/List/ListBranchesCommand.cs b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/BranchGroup/List/ListBranchesCommand.cs similarity index 68% rename from source/GitTool/Commands/CreativeCoders.GitTool.Commands.Branches/Commands/List/ListBranchesCommand.cs rename to source/GitTool/CreativeCoders.GitTool.Cli.Commands/BranchGroup/List/ListBranchesCommand.cs index d34b3b2..79b513d 100644 --- a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Branches/Commands/List/ListBranchesCommand.cs +++ b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/BranchGroup/List/ListBranchesCommand.cs @@ -1,27 +1,21 @@ -using System; -using System.Linq; -using System.Threading.Tasks; +using CreativeCoders.Cli.Core; using CreativeCoders.Core; using CreativeCoders.Core.Collections; using CreativeCoders.Git.Abstractions; using CreativeCoders.Git.Abstractions.Branches; -using CreativeCoders.GitTool.Commands.Shared.CommandExecuting; using CreativeCoders.SysConsole.Core.Abstractions; using JetBrains.Annotations; -namespace CreativeCoders.GitTool.Commands.Branches.Commands.List; +namespace CreativeCoders.GitTool.Cli.Commands.BranchGroup.List; [UsedImplicitly] -public class ListBranchesCommand : IGitToolCommandWithOptions +[CliCommand([BranchCommandGroup.Name, "list"], Description = "Lists all branches")] +public class ListBranchesCommand(ISysConsole sysConsole, IGitRepository gitRepository) + : ICliCommand { - private readonly ISysConsole _sysConsole; + private readonly ISysConsole _sysConsole = Ensure.NotNull(sysConsole); - public ListBranchesCommand(ISysConsole sysConsole) - { - _sysConsole = Ensure.NotNull(sysConsole); - } - - private void PrintBranch(IGitRepository gitRepository, IGitBranch branch, int column0Width, int column1Width) + private void PrintBranch(IGitBranch branch, int column0Width, int column1Width) { var isHead = branch.Equals(gitRepository.Head); @@ -42,7 +36,7 @@ private void PrintBranch(IGitRepository gitRepository, IGitBranch branch, int co .ResetColor(); } - public Task ExecuteAsync(IGitRepository gitRepository, ListBranchesOptions options) + public Task ExecuteAsync(ListBranchesOptions options) { _sysConsole .WriteLine() @@ -64,10 +58,10 @@ public Task ExecuteAsync(IGitRepository gitRepository, ListBranchesOptions $" {"Friendly".PadRight(column0Width)} {"Canonical".PadRight(column1Width)} Tracked remote branch"); // ReSharper disable once AccessToDisposedClosure - branches.ForEach(branch => PrintBranch(gitRepository, branch, column0Width, column1Width)); + branches.ForEach(branch => PrintBranch(branch, column0Width, column1Width)); _sysConsole.WriteLine(); - return Task.FromResult(0); + return Task.FromResult(CommandResult.Success); } } diff --git a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Branches/Commands/List/ListBranchesOptions.cs b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/BranchGroup/List/ListBranchesOptions.cs similarity index 80% rename from source/GitTool/Commands/CreativeCoders.GitTool.Commands.Branches/Commands/List/ListBranchesOptions.cs rename to source/GitTool/CreativeCoders.GitTool.Cli.Commands/BranchGroup/List/ListBranchesOptions.cs index 98f0a4f..1a3fd4a 100644 --- a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Branches/Commands/List/ListBranchesOptions.cs +++ b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/BranchGroup/List/ListBranchesOptions.cs @@ -1,7 +1,7 @@ using CreativeCoders.SysConsole.Cli.Parsing; using JetBrains.Annotations; -namespace CreativeCoders.GitTool.Commands.Branches.Commands.List; +namespace CreativeCoders.GitTool.Cli.Commands.BranchGroup.List; [PublicAPI] public class ListBranchesOptions diff --git a/source/GitTool/CreativeCoders.GitTool.Cli.Commands/BranchGroup/Pull/PullBranchCommand.cs b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/BranchGroup/Pull/PullBranchCommand.cs new file mode 100644 index 0000000..69a1791 --- /dev/null +++ b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/BranchGroup/Pull/PullBranchCommand.cs @@ -0,0 +1,20 @@ +using CreativeCoders.Cli.Core; +using CreativeCoders.Core; +using CreativeCoders.Git.Abstractions; +using JetBrains.Annotations; +using IGitToolPullCommand = CreativeCoders.GitTool.Cli.Commands.Shared.IGitToolPullCommand; + +namespace CreativeCoders.GitTool.Cli.Commands.BranchGroup.Pull; + +[UsedImplicitly] +[CliCommand([BranchCommandGroup.Name, "pull"], Description = "Pulls the current branch from remote")] +public class PullBranchCommand(IGitToolPullCommand pullCommand, IGitRepository gitRepository) + : ICliCommand +{ + private readonly IGitToolPullCommand _pullCommand = Ensure.NotNull(pullCommand); + + public async Task ExecuteAsync(PullBranchOptions options) + { + return await _pullCommand.ExecuteAsync(gitRepository, options.Verbose).ConfigureAwait(false); + } +} diff --git a/source/GitTool/CreativeCoders.GitTool.Cli.Commands/BranchGroup/Pull/PullBranchOptions.cs b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/BranchGroup/Pull/PullBranchOptions.cs new file mode 100644 index 0000000..480c0b4 --- /dev/null +++ b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/BranchGroup/Pull/PullBranchOptions.cs @@ -0,0 +1,10 @@ +using CreativeCoders.SysConsole.Cli.Parsing; +using JetBrains.Annotations; + +namespace CreativeCoders.GitTool.Cli.Commands.BranchGroup.Pull; + +[PublicAPI] +public class PullBranchOptions +{ + [OptionParameter('v', "verbose")] public bool Verbose { get; set; } +} diff --git a/source/GitTool/CreativeCoders.GitTool.Cli.Commands/BranchGroup/Push/PushBranchCommand.cs b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/BranchGroup/Push/PushBranchCommand.cs new file mode 100644 index 0000000..e36cc65 --- /dev/null +++ b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/BranchGroup/Push/PushBranchCommand.cs @@ -0,0 +1,22 @@ +using CreativeCoders.Cli.Core; +using CreativeCoders.Core; +using CreativeCoders.Git.Abstractions; +using JetBrains.Annotations; +using IGitToolPushCommand = CreativeCoders.GitTool.Cli.Commands.Shared.IGitToolPushCommand; + +namespace CreativeCoders.GitTool.Cli.Commands.BranchGroup.Push; + +[UsedImplicitly] +[CliCommand([BranchCommandGroup.Name, "push"], Description = "Pushes the current branch to remote")] +public class PushBranchCommand(IGitToolPushCommand pushCommand, IGitRepository gitRepository) + : ICliCommand +{ + private readonly IGitToolPushCommand _pushCommand = Ensure.NotNull(pushCommand); + + public async Task ExecuteAsync(PushBranchOptions options) + { + return await _pushCommand + .ExecuteAsync(gitRepository, options.CreateRemoteBranchIfNotExists, options.ConfirmPush, options.Verbose) + .ConfigureAwait(false); + } +} diff --git a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Branches/Commands/Push/PushBranchOptions.cs b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/BranchGroup/Push/PushBranchOptions.cs similarity index 78% rename from source/GitTool/Commands/CreativeCoders.GitTool.Commands.Branches/Commands/Push/PushBranchOptions.cs rename to source/GitTool/CreativeCoders.GitTool.Cli.Commands/BranchGroup/Push/PushBranchOptions.cs index b131692..2a7e92a 100644 --- a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Branches/Commands/Push/PushBranchOptions.cs +++ b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/BranchGroup/Push/PushBranchOptions.cs @@ -1,7 +1,7 @@ using CreativeCoders.SysConsole.Cli.Parsing; using JetBrains.Annotations; -namespace CreativeCoders.GitTool.Commands.Branches.Commands.Push; +namespace CreativeCoders.GitTool.Cli.Commands.BranchGroup.Push; [PublicAPI] public class PushBranchOptions @@ -14,6 +14,5 @@ public class PushBranchOptions [OptionParameter('c', "confirm", HelpText = "Confirm push if remote branch exists and there are commits to push")] public bool ConfirmPush { get; set; } - [OptionParameter('v', "verbose")] - public bool Verbose { get; set; } + [OptionParameter('v', "verbose")] public bool Verbose { get; set; } } diff --git a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Branches/Commands/Update/UpdateBranchesCommand.cs b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/BranchGroup/Update/UpdateBranchesCommand.cs similarity index 69% rename from source/GitTool/Commands/CreativeCoders.GitTool.Commands.Branches/Commands/Update/UpdateBranchesCommand.cs rename to source/GitTool/CreativeCoders.GitTool.Cli.Commands/BranchGroup/Update/UpdateBranchesCommand.cs index c09b1e8..254e371 100644 --- a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Branches/Commands/Update/UpdateBranchesCommand.cs +++ b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/BranchGroup/Update/UpdateBranchesCommand.cs @@ -1,38 +1,36 @@ -using System.Collections.Generic; -using System.Threading.Tasks; +using CreativeCoders.Cli.Core; using CreativeCoders.Core; using CreativeCoders.Core.Collections; using CreativeCoders.Git.Abstractions; using CreativeCoders.Git.Abstractions.Branches; using CreativeCoders.GitTool.Base.Configurations; using CreativeCoders.GitTool.Base.Output; -using CreativeCoders.GitTool.Commands.Shared; -using CreativeCoders.GitTool.Commands.Shared.CommandExecuting; using JetBrains.Annotations; using Spectre.Console; +using IGitToolPullCommand = CreativeCoders.GitTool.Cli.Commands.Shared.IGitToolPullCommand; -namespace CreativeCoders.GitTool.Commands.Branches.Commands.Update; +namespace CreativeCoders.GitTool.Cli.Commands.BranchGroup.Update; [UsedImplicitly] -public class UpdateBranchesCommand : IGitToolCommandWithOptions +[CliCommand([BranchCommandGroup.Name, "update"], + Description = "Update all permanent local branches by pulling from remote branches")] +public class UpdateBranchesCommand( + IRepositoryConfigurations repositoryConfigurations, + IGitToolPullCommand pullCommand, + IAnsiConsole ansiConsole, + ICml cml, + IGitRepository gitRepository) + : ICliCommand { - private readonly IAnsiConsole _ansiConsole; - private readonly ICml _cml; + private readonly IAnsiConsole _ansiConsole = Ensure.NotNull(ansiConsole); - private readonly IGitToolPullCommand _pullCommand; + private readonly ICml _cml = Ensure.NotNull(cml); - private readonly IRepositoryConfigurations _repositoryConfigurations; + private readonly IGitToolPullCommand _pullCommand = Ensure.NotNull(pullCommand); - public UpdateBranchesCommand(IRepositoryConfigurations repositoryConfigurations, IGitToolPullCommand pullCommand, - IAnsiConsole ansiConsole, ICml cml) - { - _cml = Ensure.NotNull(cml); - _ansiConsole = Ensure.NotNull(ansiConsole); - _repositoryConfigurations = Ensure.NotNull(repositoryConfigurations); - _pullCommand = Ensure.NotNull(pullCommand); - } + private readonly IRepositoryConfigurations _repositoryConfigurations = Ensure.NotNull(repositoryConfigurations); - public async Task ExecuteAsync(IGitRepository gitRepository, UpdateBranchesOptions options) + public async Task ExecuteAsync(UpdateBranchesOptions options) { Ensure.NotNull(options); @@ -75,7 +73,7 @@ public async Task ExecuteAsync(IGitRepository gitRepository, UpdateBranches _ansiConsole.EmptyLine(); - return 0; + return CommandResult.Success; } private async Task UpdateBranchesAsync(IGitRepository repository, IEnumerable updateBranchNames) diff --git a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Branches/Commands/Update/UpdateBranchesOptions.cs b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/BranchGroup/Update/UpdateBranchesOptions.cs similarity index 66% rename from source/GitTool/Commands/CreativeCoders.GitTool.Commands.Branches/Commands/Update/UpdateBranchesOptions.cs rename to source/GitTool/CreativeCoders.GitTool.Cli.Commands/BranchGroup/Update/UpdateBranchesOptions.cs index 7a21237..969a41d 100644 --- a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Branches/Commands/Update/UpdateBranchesOptions.cs +++ b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/BranchGroup/Update/UpdateBranchesOptions.cs @@ -1,6 +1,6 @@ using JetBrains.Annotations; -namespace CreativeCoders.GitTool.Commands.Branches.Commands.Update; +namespace CreativeCoders.GitTool.Cli.Commands.BranchGroup.Update; public class UpdateBranchesOptions { diff --git a/source/GitTool/CreativeCoders.GitTool.Cli.Commands/CreativeCoders.GitTool.Cli.Commands.csproj b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/CreativeCoders.GitTool.Cli.Commands.csproj new file mode 100644 index 0000000..aa68630 --- /dev/null +++ b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/CreativeCoders.GitTool.Cli.Commands.csproj @@ -0,0 +1,18 @@ + + + + net10.0 + enable + enable + + + + + + + + + + + + diff --git a/source/GitTool/CreativeCoders.GitTool.Cli.Commands/FeatureGroup/FeatureCommandGroup.cs b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/FeatureGroup/FeatureCommandGroup.cs new file mode 100644 index 0000000..80f0fe6 --- /dev/null +++ b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/FeatureGroup/FeatureCommandGroup.cs @@ -0,0 +1,10 @@ +using CreativeCoders.Cli.Core; + +[assembly: CliCommandGroup(["feature"], "Commands for managing features")] + +namespace CreativeCoders.GitTool.Cli.Commands.FeatureGroup; + +public static class FeatureCommandGroup +{ + public const string Name = "feature"; +} diff --git a/source/GitTool/CreativeCoders.GitTool.Cli.Commands/FeatureGroup/Finish/FeatureFinishFailedException.cs b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/FeatureGroup/Finish/FeatureFinishFailedException.cs new file mode 100644 index 0000000..e99744b --- /dev/null +++ b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/FeatureGroup/Finish/FeatureFinishFailedException.cs @@ -0,0 +1,11 @@ +using CreativeCoders.Cli.Hosting.Exceptions; + +namespace CreativeCoders.GitTool.Cli.Commands.FeatureGroup.Finish; + +public class FeatureFinishFailedException : CliExitException +{ + public FeatureFinishFailedException(string message, int exitCode, Exception? exception = null) : base(message, + exitCode, exception) + { + } +} diff --git a/source/GitTool/CreativeCoders.GitTool.Cli.Commands/FeatureGroup/Finish/FinishFeatureCommand.cs b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/FeatureGroup/Finish/FinishFeatureCommand.cs new file mode 100644 index 0000000..50148a6 --- /dev/null +++ b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/FeatureGroup/Finish/FinishFeatureCommand.cs @@ -0,0 +1,61 @@ +using CreativeCoders.Cli.Core; +using CreativeCoders.Core; +using CreativeCoders.Git.Abstractions; +using CreativeCoders.GitTool.Base.Configurations; +using JetBrains.Annotations; +using Spectre.Console; + +namespace CreativeCoders.GitTool.Cli.Commands.FeatureGroup.Finish; + +[UsedImplicitly] +[CliCommand([FeatureCommandGroup.Name, "finish"], Description = "Finish a feature branch and create a pull request")] +public class FinishFeatureCommand( + IAnsiConsole ansiConsole, + IRepositoryConfigurations repositoryConfigurations, + IFinishFeatureSteps finishFeatureSteps, + IGitRepository gitRepository) + : ICliCommand +{ + private readonly IFinishFeatureSteps _finishFeatureSteps = Ensure.NotNull(finishFeatureSteps); + + private readonly IRepositoryConfigurations _repositoryConfigurations = Ensure.NotNull(repositoryConfigurations); + + private FinishFeatureData CreateData(FinishFeatureOptions options) + { + var configuration = _repositoryConfigurations.GetConfiguration(gitRepository); + + return new FinishFeatureData(gitRepository, configuration.GetFeatureBranchName(options.FeatureName), + configuration.GetDefaultBranchName(gitRepository.Info.MainBranch), configuration.GitServiceProviderName, + options.PullRequestTitle); + } + + public async Task ExecuteAsync(FinishFeatureOptions options) + { + var data = CreateData(options); + + try + { + _finishFeatureSteps.UpdateFeatureBranch(data); + + _finishFeatureSteps.MergeDefaultBranch(data); + + await _finishFeatureSteps.PushFeatureBranch(data).ConfigureAwait(false); + + // Ensure remote branch creation and use it for pull request + + await _finishFeatureSteps.CreatePullRequest(data).ConfigureAwait(false); + } + catch (FeatureFinishFailedException e) + { + ansiConsole.MarkupLine($"[red]{e.Message}[/]"); + + return e.ExitCode; + } + + gitRepository.Branches.CheckOut(data.DefaultBranch); + + gitRepository.Branches.DeleteLocalBranch(data.FeatureBranch); + + return CommandResult.Success; + } +} diff --git a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Features/Commands/FinishFeature/FinishFeatureData.cs b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/FeatureGroup/Finish/FinishFeatureData.cs similarity index 90% rename from source/GitTool/Commands/CreativeCoders.GitTool.Commands.Features/Commands/FinishFeature/FinishFeatureData.cs rename to source/GitTool/CreativeCoders.GitTool.Cli.Commands/FeatureGroup/Finish/FinishFeatureData.cs index e671bd1..b29afd9 100644 --- a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Features/Commands/FinishFeature/FinishFeatureData.cs +++ b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/FeatureGroup/Finish/FinishFeatureData.cs @@ -1,6 +1,6 @@ using CreativeCoders.Git.Abstractions; -namespace CreativeCoders.GitTool.Commands.Features.Commands.FinishFeature; +namespace CreativeCoders.GitTool.Cli.Commands.FeatureGroup.Finish; public class FinishFeatureData { @@ -23,4 +23,4 @@ public FinishFeatureData(IGitRepository repository, string featureBranch, string public string? PullRequestTitle { get; } public IGitRepository Repository { get; } -} \ No newline at end of file +} diff --git a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Features/Commands/FinishFeature/FinishFeatureOptions.cs b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/FeatureGroup/Finish/FinishFeatureOptions.cs similarity index 67% rename from source/GitTool/Commands/CreativeCoders.GitTool.Commands.Features/Commands/FinishFeature/FinishFeatureOptions.cs rename to source/GitTool/CreativeCoders.GitTool.Cli.Commands/FeatureGroup/Finish/FinishFeatureOptions.cs index 44782fb..0f59f69 100644 --- a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Features/Commands/FinishFeature/FinishFeatureOptions.cs +++ b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/FeatureGroup/Finish/FinishFeatureOptions.cs @@ -1,15 +1,14 @@ using CreativeCoders.SysConsole.Cli.Parsing; using JetBrains.Annotations; -namespace CreativeCoders.GitTool.Commands.Features.Commands.FinishFeature; +namespace CreativeCoders.GitTool.Cli.Commands.FeatureGroup.Finish; [PublicAPI] public class FinishFeatureOptions { private const string PullRequestTitleName = "prtitle"; - [OptionValue(0, IsRequired = true)] - public string FeatureName { get; set; } = null!; + [OptionValue(0, IsRequired = true)] public string FeatureName { get; set; } = null!; [OptionParameter('t', PullRequestTitleName, HelpText = "Title for pull request that is created")] public string? PullRequestTitle { get; set; } diff --git a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Features/Commands/FinishFeature/FinishFeatureSteps.cs b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/FeatureGroup/Finish/FinishFeatureSteps.cs similarity index 71% rename from source/GitTool/Commands/CreativeCoders.GitTool.Commands.Features/Commands/FinishFeature/FinishFeatureSteps.cs rename to source/GitTool/CreativeCoders.GitTool.Cli.Commands/FeatureGroup/Finish/FinishFeatureSteps.cs index 0cd264b..ee7de64 100644 --- a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Features/Commands/FinishFeature/FinishFeatureSteps.cs +++ b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/FeatureGroup/Finish/FinishFeatureSteps.cs @@ -1,30 +1,24 @@ -using System.Threading.Tasks; -using CreativeCoders.Core; +using CreativeCoders.Core; using CreativeCoders.Git.Abstractions; using CreativeCoders.Git.Abstractions.Commits; using CreativeCoders.GitTool.Base; using CreativeCoders.GitTool.Base.Exceptions; -using CreativeCoders.GitTool.Commands.Shared; -using CreativeCoders.SysConsole.App; using CreativeCoders.SysConsole.Core.Abstractions; +using IGitToolPushCommand = CreativeCoders.GitTool.Cli.Commands.Shared.IGitToolPushCommand; -namespace CreativeCoders.GitTool.Commands.Features.Commands.FinishFeature; +namespace CreativeCoders.GitTool.Cli.Commands.FeatureGroup.Finish; -public class FinishFeatureSteps : IFinishFeatureSteps +public class FinishFeatureSteps( + ISysConsole sysConsole, + IGitServiceProviders gitServiceProviders, + IGitToolPushCommand pushCommand) + : IFinishFeatureSteps { - private readonly IGitServiceProviders _gitServiceProviders; + private readonly IGitServiceProviders _gitServiceProviders = Ensure.NotNull(gitServiceProviders); - private readonly ISysConsole _sysConsole; + private readonly ISysConsole _sysConsole = Ensure.NotNull(sysConsole); - private readonly IGitToolPushCommand _pushCommand; - - public FinishFeatureSteps(ISysConsole sysConsole, IGitServiceProviders gitServiceProviders, - IGitToolPushCommand pushCommand) - { - _sysConsole = Ensure.NotNull(sysConsole, nameof(sysConsole)); - _gitServiceProviders = Ensure.NotNull(gitServiceProviders, nameof(gitServiceProviders)); - _pushCommand = Ensure.NotNull(pushCommand, nameof(pushCommand)); - } + private readonly IGitToolPushCommand _pushCommand = Ensure.NotNull(pushCommand); public void UpdateFeatureBranch(FinishFeatureData data) { @@ -38,8 +32,8 @@ public void UpdateFeatureBranch(FinishFeatureData data) .WriteLineError("Feature branch has uncommitted changes. Please commit or revert and try again") .WriteLine(); - throw new ConsoleException(ReturnCodes.BranchHasUncommittedChanges, - "Feature branch has uncommitted changes"); + throw new FeatureFinishFailedException("Feature branch has uncommitted changes", + ReturnCodes.BranchHasUncommittedChanges); } _sysConsole @@ -64,8 +58,8 @@ public void UpdateFeatureBranch(FinishFeatureData data) .WriteLineError("Pull feature branch updates from remote caused merge conflicts") .WriteLineError("Resolve conflicts and try again"); - throw new ConsoleException(ReturnCodes.MergeConflicts, - "Merge feature branch from remote into local caused merge conflicts"); + throw new FeatureFinishFailedException("Merge feature branch from remote into local caused merge conflicts", + ReturnCodes.MergeConflicts); } _sysConsole @@ -92,8 +86,8 @@ public void MergeDefaultBranch(FinishFeatureData data) .WriteLineError("Pull default branch updates from remote caused merge conflicts") .WriteLineError("Resolve conflicts and try again"); - throw new ConsoleException(ReturnCodes.MergeConflicts, - "Merge default branch from remote into local caused merge conflicts"); + throw new FeatureFinishFailedException("Merge default branch from remote into local caused merge conflicts", + ReturnCodes.MergeConflicts); } _sysConsole @@ -108,8 +102,8 @@ public void MergeDefaultBranch(FinishFeatureData data) .WriteLineError("Merge default branch to feature branch caused merge conflicts") .WriteLineError("Resolve conflicts and try again"); - throw new ConsoleException(ReturnCodes.MergeConflicts, - "Merge default branch to feature branch caused merge conflicts"); + throw new FeatureFinishFailedException("Merge default branch to feature branch caused merge conflicts", + ReturnCodes.MergeConflicts); } data.Repository.Branches.CheckOut(data.FeatureBranch); @@ -132,7 +126,8 @@ public async Task PushFeatureBranch(FinishFeatureData data) public async Task CreatePullRequest(FinishFeatureData data) { - var provider = await _gitServiceProviders.GetServiceProviderAsync(data.Repository, data.RepositoryGitServiceProviderName); + var provider = + await _gitServiceProviders.GetServiceProviderAsync(data.Repository, data.RepositoryGitServiceProviderName); if (await provider.PullRequestExists(data.Repository.Info.RemoteUri, data.FeatureBranch, data.DefaultBranch)) @@ -162,7 +157,7 @@ public async Task CreatePullRequest(FinishFeatureData data) .WriteLineError(e.Message.Trim()) .WriteLine(); - throw new ConsoleException(ReturnCodes.GeneralError, "Create pull request failed"); + throw new FeatureFinishFailedException("Create pull request failed", ReturnCodes.GeneralError); } } -} \ No newline at end of file +} diff --git a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Features/Commands/FinishFeature/IFinishFeatureSteps.cs b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/FeatureGroup/Finish/IFinishFeatureSteps.cs similarity index 69% rename from source/GitTool/Commands/CreativeCoders.GitTool.Commands.Features/Commands/FinishFeature/IFinishFeatureSteps.cs rename to source/GitTool/CreativeCoders.GitTool.Cli.Commands/FeatureGroup/Finish/IFinishFeatureSteps.cs index 1126c91..08c2f58 100644 --- a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Features/Commands/FinishFeature/IFinishFeatureSteps.cs +++ b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/FeatureGroup/Finish/IFinishFeatureSteps.cs @@ -1,6 +1,4 @@ -using System.Threading.Tasks; - -namespace CreativeCoders.GitTool.Commands.Features.Commands.FinishFeature; +namespace CreativeCoders.GitTool.Cli.Commands.FeatureGroup.Finish; public interface IFinishFeatureSteps { @@ -11,4 +9,4 @@ public interface IFinishFeatureSteps void MergeDefaultBranch(FinishFeatureData data); Task CreatePullRequest(FinishFeatureData data); -} \ No newline at end of file +} diff --git a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Features/ServiceCollectionExtensions.cs b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/FeatureGroup/ServiceCollectionExtensions.cs similarity index 72% rename from source/GitTool/Commands/CreativeCoders.GitTool.Commands.Features/ServiceCollectionExtensions.cs rename to source/GitTool/CreativeCoders.GitTool.Cli.Commands/FeatureGroup/ServiceCollectionExtensions.cs index 61ff829..dc85bc6 100644 --- a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Features/ServiceCollectionExtensions.cs +++ b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/FeatureGroup/ServiceCollectionExtensions.cs @@ -1,8 +1,8 @@ -using CreativeCoders.GitTool.Commands.Features.Commands.FinishFeature; +using CreativeCoders.GitTool.Cli.Commands.FeatureGroup.Finish; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection.Extensions; -namespace CreativeCoders.GitTool.Commands.Features; +namespace CreativeCoders.GitTool.Cli.Commands.FeatureGroup; public static class ServiceCollectionExtensions { diff --git a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Features/Commands/StartFeature/StartFeatureCommand.cs b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/FeatureGroup/Start/StartFeatureCommand.cs similarity index 59% rename from source/GitTool/Commands/CreativeCoders.GitTool.Commands.Features/Commands/StartFeature/StartFeatureCommand.cs rename to source/GitTool/CreativeCoders.GitTool.Cli.Commands/FeatureGroup/Start/StartFeatureCommand.cs index 167c72f..39750bc 100644 --- a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Features/Commands/StartFeature/StartFeatureCommand.cs +++ b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/FeatureGroup/Start/StartFeatureCommand.cs @@ -1,32 +1,29 @@ -using System.Threading.Tasks; +using CreativeCoders.Cli.Core; using CreativeCoders.Core; using CreativeCoders.Core.Collections; using CreativeCoders.Git.Abstractions; using CreativeCoders.GitTool.Base; using CreativeCoders.GitTool.Base.Configurations; -using CreativeCoders.GitTool.Commands.Shared; -using CreativeCoders.GitTool.Commands.Shared.CommandExecuting; using CreativeCoders.SysConsole.Core.Abstractions; using JetBrains.Annotations; +using IGitToolPullCommand = CreativeCoders.GitTool.Cli.Commands.Shared.IGitToolPullCommand; -namespace CreativeCoders.GitTool.Commands.Features.Commands.StartFeature; +namespace CreativeCoders.GitTool.Cli.Commands.FeatureGroup.Start; [UsedImplicitly] -public class StartFeatureCommand : IGitToolCommandWithOptions +[CliCommand([FeatureCommandGroup.Name, "start"], Description = "Start a new feature branch")] +public class StartFeatureCommand( + ISysConsole sysConsole, + IRepositoryConfigurations repositoryConfigurations, + IGitToolPullCommand pullCommand, + IGitRepository gitRepository) + : ICliCommand { - private readonly IGitToolPullCommand _pullCommand; - private readonly IRepositoryConfigurations _repositoryConfigurations; + private readonly IGitToolPullCommand _pullCommand = Ensure.NotNull(pullCommand); - private readonly ISysConsole _sysConsole; + private readonly IRepositoryConfigurations _repositoryConfigurations = Ensure.NotNull(repositoryConfigurations); - public StartFeatureCommand(ISysConsole sysConsole, - IRepositoryConfigurations repositoryConfigurations, - IGitToolPullCommand pullCommand) - { - _repositoryConfigurations = Ensure.NotNull(repositoryConfigurations); - _sysConsole = Ensure.NotNull(sysConsole); - _pullCommand = Ensure.NotNull(pullCommand); - } + private readonly ISysConsole _sysConsole = Ensure.NotNull(sysConsole); private void PrintStartFeatureData(StartFeatureData data) { @@ -37,7 +34,7 @@ private void PrintStartFeatureData(StartFeatureData data) private void CheckIfFeatureBranchExists(StartFeatureData data) { - var branch = data.GitRepository.Branches[data.FeatureBranch]; + var branch = gitRepository.Branches[data.FeatureBranch]; if (branch != null) { @@ -48,14 +45,14 @@ private void CheckIfFeatureBranchExists(StartFeatureData data) //data.GitRepository.Remotes[data.FeatureBranch] } - private void CreateAndCheckOutFeatureBranch(IGitRepository repository, - StartFeatureOptions options, RepositoryConfiguration repositoryConfiguration) + private void CreateAndCheckOutFeatureBranch(StartFeatureOptions options, + RepositoryConfiguration repositoryConfiguration) { var featureBranchName = repositoryConfiguration.GetFeatureBranchName(options.FeatureName); _sysConsole.WriteLine($"Creating feature branch '{featureBranchName}' ..."); - var featureBranch = repository.Branches.CreateBranch(featureBranchName); + var featureBranch = gitRepository.Branches.CreateBranch(featureBranchName); if (featureBranch == null) { @@ -69,7 +66,7 @@ private void CreateAndCheckOutFeatureBranch(IGitRepository repository, .WriteLine() .WriteLine("Checking out feature branch..."); - var checkedOutBranch = repository.Branches.CheckOut(featureBranch.Name.Canonical); + var checkedOutBranch = gitRepository.Branches.CheckOut(featureBranch.Name.Canonical); if (checkedOutBranch == null) { @@ -83,10 +80,9 @@ private void CreateAndCheckOutFeatureBranch(IGitRepository repository, .WriteLine(); } - private async Task CheckOutAndUpdateBaseBranch(IGitRepository repository, - RepositoryConfiguration repositoryConfiguration) + private async Task CheckOutAndUpdateBaseBranch(RepositoryConfiguration repositoryConfiguration) { - var baseBranchName = repositoryConfiguration.GetDefaultBranchName(repository.Info.MainBranch); + var baseBranchName = repositoryConfiguration.GetDefaultBranchName(gitRepository.Info.MainBranch); if (string.IsNullOrEmpty(baseBranchName)) { @@ -95,7 +91,7 @@ private async Task CheckOutAndUpdateBaseBranch(IGitRepository repository, .WriteLine() .WriteLine("Existing branches:"); - repository.Branches.ForEach(branch => + gitRepository.Branches.ForEach(branch => _sysConsole.WriteLine($" {branch.Name.Friendly} -> {branch.TrackedBranch?.Name.Friendly}")); return; @@ -103,39 +99,39 @@ private async Task CheckOutAndUpdateBaseBranch(IGitRepository repository, _sysConsole.WriteLine($"Checkout base branch '{baseBranchName}'"); - repository.Branches.CheckOut(baseBranchName); + gitRepository.Branches.CheckOut(baseBranchName); _sysConsole .WriteLine("Base branch checked out") .WriteLine() .WriteLine("Pulling from origin"); - await _pullCommand.ExecuteAsync(repository).ConfigureAwait(false); + await _pullCommand.ExecuteAsync(gitRepository).ConfigureAwait(false); - repository.Fetch("origin", new GitFetchOptions { TagFetchMode = GitTagFetchMode.All }); + gitRepository.Fetch("origin", new GitFetchOptions { TagFetchMode = GitTagFetchMode.All }); } - private StartFeatureData CreateData(IGitRepository gitRepository, StartFeatureOptions options) + private StartFeatureData CreateData(StartFeatureOptions options) { var configuration = _repositoryConfigurations.GetConfiguration(gitRepository); - return new StartFeatureData(gitRepository, configuration.GetFeatureBranchName(options.FeatureName), + return new StartFeatureData(configuration.GetFeatureBranchName(options.FeatureName), configuration.GetDefaultBranchName(gitRepository.Info.MainBranch)); } - public async Task ExecuteAsync(IGitRepository gitRepository, StartFeatureOptions options) + public async Task ExecuteAsync(StartFeatureOptions options) { var configuration = _repositoryConfigurations.GetConfiguration(gitRepository); - var data = CreateData(gitRepository, options); + var data = CreateData(options); PrintStartFeatureData(data); CheckIfFeatureBranchExists(data); - await CheckOutAndUpdateBaseBranch(gitRepository, configuration).ConfigureAwait(false); + await CheckOutAndUpdateBaseBranch(configuration).ConfigureAwait(false); - CreateAndCheckOutFeatureBranch(gitRepository, options, configuration); + CreateAndCheckOutFeatureBranch(options, configuration); if (options.PushAfterCreate) { diff --git a/source/GitTool/CreativeCoders.GitTool.Cli.Commands/FeatureGroup/Start/StartFeatureData.cs b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/FeatureGroup/Start/StartFeatureData.cs new file mode 100644 index 0000000..cd0b8db --- /dev/null +++ b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/FeatureGroup/Start/StartFeatureData.cs @@ -0,0 +1,8 @@ +namespace CreativeCoders.GitTool.Cli.Commands.FeatureGroup.Start; + +public class StartFeatureData(string featureBranch, string defaultBranch) +{ + public string FeatureBranch { get; } = featureBranch; + + public string DefaultBranch { get; } = defaultBranch; +} diff --git a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Features/Commands/StartFeature/StartFeatureOptions.cs b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/FeatureGroup/Start/StartFeatureOptions.cs similarity index 63% rename from source/GitTool/Commands/CreativeCoders.GitTool.Commands.Features/Commands/StartFeature/StartFeatureOptions.cs rename to source/GitTool/CreativeCoders.GitTool.Cli.Commands/FeatureGroup/Start/StartFeatureOptions.cs index 1907373..7f2c09b 100644 --- a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Features/Commands/StartFeature/StartFeatureOptions.cs +++ b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/FeatureGroup/Start/StartFeatureOptions.cs @@ -1,15 +1,14 @@ using CreativeCoders.SysConsole.Cli.Parsing; using JetBrains.Annotations; -namespace CreativeCoders.GitTool.Commands.Features.Commands.StartFeature; +namespace CreativeCoders.GitTool.Cli.Commands.FeatureGroup.Start; [PublicAPI] public class StartFeatureOptions { private const string PushAfterCreateName = "pushaftercreate"; - [OptionValue(0, IsRequired = true)] - public string FeatureName { get; set; } = null!; + [OptionValue(0, IsRequired = true)] public string FeatureName { get; set; } = null!; [OptionParameter('p', PushAfterCreateName)] public bool PushAfterCreate { get; set; } diff --git a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Releases/Commands/Create/CreateReleaseCommand.cs b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/ReleaseGroup/Create/CreateReleaseCommand.cs similarity index 71% rename from source/GitTool/Commands/CreativeCoders.GitTool.Commands.Releases/Commands/Create/CreateReleaseCommand.cs rename to source/GitTool/CreativeCoders.GitTool.Cli.Commands/ReleaseGroup/Create/CreateReleaseCommand.cs index 2fca885..4361f5e 100644 --- a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Releases/Commands/Create/CreateReleaseCommand.cs +++ b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/ReleaseGroup/Create/CreateReleaseCommand.cs @@ -1,27 +1,25 @@ -using System.Threading.Tasks; +using CreativeCoders.Cli.Core; using CreativeCoders.Core; using CreativeCoders.Git.Abstractions; using CreativeCoders.Git.Abstractions.Branches; using CreativeCoders.GitTool.Base; -using CreativeCoders.GitTool.Commands.Shared.CommandExecuting; using CreativeCoders.SysConsole.Core.Abstractions; using JetBrains.Annotations; -namespace CreativeCoders.GitTool.Commands.Releases.Commands.Create; +namespace CreativeCoders.GitTool.Cli.Commands.ReleaseGroup.Create; [UsedImplicitly] -public class CreateReleaseCommand : IGitToolCommandWithOptions +[CliCommand([ReleaseCommandGroup.Name, "create"], + Description = "Creates a release by creating a version tag")] +public class CreateReleaseCommand( + ISysConsole sysConsole, + IGitServiceProviders gitServiceProviders, + IGitRepository gitRepository) + : ICliCommand { - private readonly IGitServiceProviders _gitServiceProviders; + private readonly IGitServiceProviders _gitServiceProviders = Ensure.NotNull(gitServiceProviders); - private readonly ISysConsole _sysConsole; - - public CreateReleaseCommand(ISysConsole sysConsole, - IGitServiceProviders gitServiceProviders) - { - _sysConsole = Ensure.NotNull(sysConsole); - _gitServiceProviders = Ensure.NotNull(gitServiceProviders); - } + private readonly ISysConsole _sysConsole = Ensure.NotNull(sysConsole); private async Task MergeDevelopToMain(IGitRepository repository, string mainBranchName, CreateReleaseOptions options) @@ -34,7 +32,7 @@ private async Task MergeDevelopToMain(IGitRepository repository, string mainBran _ = await provider.CreatePullRequestAsync(createPullRequest); } - public async Task ExecuteAsync(IGitRepository gitRepository, CreateReleaseOptions options) + public async Task ExecuteAsync(CreateReleaseOptions options) { var mainBranchName = GitBranchNames.Local.GetCanonicalName(gitRepository.Info.MainBranch); @@ -69,6 +67,6 @@ public async Task ExecuteAsync(IGitRepository gitRepository, CreateReleaseO gitRepository.Tags.PushTag(versionTag); } - return 0; + return CommandResult.Success; } } diff --git a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Releases/Commands/Create/CreateReleaseOptions.cs b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/ReleaseGroup/Create/CreateReleaseOptions.cs similarity index 65% rename from source/GitTool/Commands/CreativeCoders.GitTool.Commands.Releases/Commands/Create/CreateReleaseOptions.cs rename to source/GitTool/CreativeCoders.GitTool.Cli.Commands/ReleaseGroup/Create/CreateReleaseOptions.cs index 78468b3..9d37fb3 100644 --- a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Releases/Commands/Create/CreateReleaseOptions.cs +++ b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/ReleaseGroup/Create/CreateReleaseOptions.cs @@ -1,15 +1,14 @@ using CreativeCoders.SysConsole.Cli.Parsing; using JetBrains.Annotations; -namespace CreativeCoders.GitTool.Commands.Releases.Commands.Create; +namespace CreativeCoders.GitTool.Cli.Commands.ReleaseGroup.Create; [PublicAPI] public class CreateReleaseOptions { private const string PushAllTagsLongName = "alltags"; - [OptionValue(0, IsRequired = true)] - public string? Version { get; set; } + [OptionValue(0, IsRequired = true)] public string? Version { get; set; } [OptionParameter('a', PushAllTagsLongName)] public bool PushAllTags { get; set; } diff --git a/source/GitTool/CreativeCoders.GitTool.Cli.Commands/ReleaseGroup/ReleaseCommandGroup.cs b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/ReleaseGroup/ReleaseCommandGroup.cs new file mode 100644 index 0000000..47405f7 --- /dev/null +++ b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/ReleaseGroup/ReleaseCommandGroup.cs @@ -0,0 +1,10 @@ +using CreativeCoders.Cli.Core; + +[assembly: CliCommandGroup(["release"], "Commands for managing releases")] + +namespace CreativeCoders.GitTool.Cli.Commands.ReleaseGroup; + +public static class ReleaseCommandGroup +{ + public const string Name = "release"; +} diff --git a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Shared/AnsiConsoleExtensions.cs b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Shared/AnsiConsoleExtensions.cs similarity index 96% rename from source/GitTool/Commands/CreativeCoders.GitTool.Commands.Shared/AnsiConsoleExtensions.cs rename to source/GitTool/CreativeCoders.GitTool.Cli.Commands/Shared/AnsiConsoleExtensions.cs index 78f43a3..68e9bbb 100644 --- a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Shared/AnsiConsoleExtensions.cs +++ b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Shared/AnsiConsoleExtensions.cs @@ -3,7 +3,7 @@ using CreativeCoders.Git.Abstractions.Commits; using Spectre.Console; -namespace CreativeCoders.GitTool.Commands.Shared; +namespace CreativeCoders.GitTool.Cli.Commands.Shared; public static class AnsiConsoleExtensions { diff --git a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Shared/GitToolPullCommand.cs b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Shared/GitToolPullCommand.cs similarity index 92% rename from source/GitTool/Commands/CreativeCoders.GitTool.Commands.Shared/GitToolPullCommand.cs rename to source/GitTool/CreativeCoders.GitTool.Cli.Commands/Shared/GitToolPullCommand.cs index 965be7c..c599576 100644 --- a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Shared/GitToolPullCommand.cs +++ b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Shared/GitToolPullCommand.cs @@ -5,7 +5,7 @@ using CreativeCoders.GitTool.Base.Output; using Spectre.Console; -namespace CreativeCoders.GitTool.Commands.Shared; +namespace CreativeCoders.GitTool.Cli.Commands.Shared; public class GitToolPullCommand : IGitToolPullCommand { @@ -15,8 +15,8 @@ public class GitToolPullCommand : IGitToolPullCommand public GitToolPullCommand(IAnsiConsole ansiConsole, ICml cml) { - _ansiConsole = Ensure.NotNull(ansiConsole, nameof(ansiConsole)); - _cml = Ensure.NotNull(cml, nameof(cml)); + _ansiConsole = Ensure.NotNull(ansiConsole); + _cml = Ensure.NotNull(cml); } public Task ExecuteAsync(IGitRepository gitRepository) @@ -51,7 +51,7 @@ public Task ExecuteAsync(IGitRepository gitRepository, bool verbose) private void CheckoutProgress(string path, int completedSteps, int totalSteps) { - _ansiConsole.MarkupLine($"{_cml.HighLight(path)} {completedSteps/totalSteps}"); + _ansiConsole.MarkupLine($"{_cml.HighLight(path)} {completedSteps / totalSteps}"); } private void PrintMergeResultStatus(GitMergeStatus mergeResultStatus) diff --git a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Shared/GitToolPushCommand.cs b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Shared/GitToolPushCommand.cs similarity index 91% rename from source/GitTool/Commands/CreativeCoders.GitTool.Commands.Shared/GitToolPushCommand.cs rename to source/GitTool/CreativeCoders.GitTool.Cli.Commands/Shared/GitToolPushCommand.cs index 93f06c1..ef9671f 100644 --- a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Shared/GitToolPushCommand.cs +++ b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Shared/GitToolPushCommand.cs @@ -6,7 +6,7 @@ using CreativeCoders.GitTool.Base.Output; using Spectre.Console; -namespace CreativeCoders.GitTool.Commands.Shared; +namespace CreativeCoders.GitTool.Cli.Commands.Shared; public class GitToolPushCommand : IGitToolPushCommand { @@ -16,15 +16,15 @@ public class GitToolPushCommand : IGitToolPushCommand public GitToolPushCommand(IAnsiConsole ansiConsole, ICml cml) { - _ansiConsole = Ensure.NotNull(ansiConsole, nameof(ansiConsole)); - _cml = Ensure.NotNull(cml, nameof(cml)); + _ansiConsole = Ensure.NotNull(ansiConsole); + _cml = Ensure.NotNull(cml); } public Task ExecuteAsync(IGitRepository gitRepository, bool createRemoteIsNotExists, bool confirmPush) => ExecuteAsync(gitRepository, createRemoteIsNotExists, confirmPush, false); - public Task ExecuteAsync(IGitRepository gitRepository, bool createRemoteIsNotExists, bool verbose, - bool confirmPush) + public Task ExecuteAsync(IGitRepository gitRepository, bool createRemoteIsNotExists, bool confirmPush, + bool verbose) { _ansiConsole .WriteMarkupLine("Push updates to remote origin") @@ -60,7 +60,7 @@ private bool DoConfirm() var key = _ansiConsole.Input.ReadKey(false); - return key is {KeyChar: 'y'}; + return key is { KeyChar: 'y' }; } private void OnGitUnPushedCommits(IEnumerable commits) diff --git a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Shared/IGitToolPullCommand.cs b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Shared/IGitToolPullCommand.cs similarity index 80% rename from source/GitTool/Commands/CreativeCoders.GitTool.Commands.Shared/IGitToolPullCommand.cs rename to source/GitTool/CreativeCoders.GitTool.Cli.Commands/Shared/IGitToolPullCommand.cs index c1c80a3..2646f6b 100644 --- a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Shared/IGitToolPullCommand.cs +++ b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Shared/IGitToolPullCommand.cs @@ -1,6 +1,6 @@ using CreativeCoders.Git.Abstractions; -namespace CreativeCoders.GitTool.Commands.Shared; +namespace CreativeCoders.GitTool.Cli.Commands.Shared; public interface IGitToolPullCommand { diff --git a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Shared/IGitToolPushCommand.cs b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Shared/IGitToolPushCommand.cs similarity index 85% rename from source/GitTool/Commands/CreativeCoders.GitTool.Commands.Shared/IGitToolPushCommand.cs rename to source/GitTool/CreativeCoders.GitTool.Cli.Commands/Shared/IGitToolPushCommand.cs index 0bd6a8f..b3d6f7d 100644 --- a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Shared/IGitToolPushCommand.cs +++ b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Shared/IGitToolPushCommand.cs @@ -1,6 +1,6 @@ using CreativeCoders.Git.Abstractions; -namespace CreativeCoders.GitTool.Commands.Shared; +namespace CreativeCoders.GitTool.Cli.Commands.Shared; public interface IGitToolPushCommand { diff --git a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Shared/ServiceCollectionExtensions.cs b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Shared/ServiceCollectionExtensions.cs similarity index 58% rename from source/GitTool/Commands/CreativeCoders.GitTool.Commands.Shared/ServiceCollectionExtensions.cs rename to source/GitTool/CreativeCoders.GitTool.Cli.Commands/Shared/ServiceCollectionExtensions.cs index abeda55..fb412aa 100644 --- a/source/GitTool/Commands/CreativeCoders.GitTool.Commands.Shared/ServiceCollectionExtensions.cs +++ b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Shared/ServiceCollectionExtensions.cs @@ -1,8 +1,7 @@ -using CreativeCoders.GitTool.Commands.Shared.CommandExecuting; -using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection.Extensions; -namespace CreativeCoders.GitTool.Commands.Shared; +namespace CreativeCoders.GitTool.Cli.Commands.Shared; public static class ServiceCollectionExtensions { @@ -11,7 +10,5 @@ public static void AddGitSharedCommands(this IServiceCollection services) services.TryAddTransient(); services.TryAddTransient(); - - services.TryAddTransient(); } } diff --git a/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Tool/Setup/SetupCommand.cs b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Tool/Setup/SetupCommand.cs new file mode 100644 index 0000000..d44a811 --- /dev/null +++ b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Tool/Setup/SetupCommand.cs @@ -0,0 +1,63 @@ +using CreativeCoders.Cli.Core; +using CreativeCoders.Git.Abstractions; +using CreativeCoders.GitTool.Base; +using CreativeCoders.GitTool.Base.Configurations; +using CreativeCoders.SysConsole.Core; +using JetBrains.Annotations; +using Spectre.Console; + +namespace CreativeCoders.GitTool.Cli.Commands.Tool.Setup; + +[UsedImplicitly] +[CliCommand(["setup"], Description = "Setup the git tool for the current repository")] +public class SetupCommand( + IAnsiConsole ansiConsole, + IGitRepository gitRepository, + IRepositoryConfigurations repositoryConfigurations, + IGitServiceProviders gitServiceProviders) : ICliCommand +{ + public async Task ExecuteAsync() + { + var configuration = repositoryConfigurations.GetConfiguration(gitRepository); + + ansiConsole.PrintBlock() + .WriteLine() + .WriteLine("Development branch (empty = no development branch)"); + + var developBranch = + await ansiConsole.PromptAsync( + new TextPrompt($"(Current value = '{configuration.DevelopBranch}'): ") + { AllowEmpty = true }); + + configuration.DevelopBranch = developBranch ?? string.Empty; + configuration.HasDevelopBranch = !string.IsNullOrEmpty(developBranch); + + var featureBranchPrefix = await ansiConsole.PromptAsync(new TextPrompt( + $"Prefix for feature branches (Empty = current value '{configuration.FeatureBranchPrefix}'): ") + { AllowEmpty = true }); + + if (!string.IsNullOrEmpty(featureBranchPrefix)) + { + configuration.FeatureBranchPrefix = featureBranchPrefix; + } + + var selectionPrompt = new SelectionPrompt(); + + var gitProviderName = + await ansiConsole.PromptAsync(selectionPrompt.AddChoices(gitServiceProviders.ProviderNames)); + + if (!string.IsNullOrEmpty(gitProviderName)) + { + configuration.GitServiceProviderName = gitProviderName; + } + + var disableCertValidationPrompt = new ConfirmationPrompt("Disable certificate check (true/false): ") + { DefaultValue = configuration.DisableCertificateValidation }; + + configuration.DisableCertificateValidation = await ansiConsole.PromptAsync(disableCertValidationPrompt); + + await repositoryConfigurations.SaveConfigurationAsync(gitRepository.Info.RemoteUri, configuration); + + return CommandResult.Success; + } +} diff --git a/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Tool/ShowConfig/ShowConfigCommand.cs b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Tool/ShowConfig/ShowConfigCommand.cs new file mode 100644 index 0000000..1199a80 --- /dev/null +++ b/source/GitTool/CreativeCoders.GitTool.Cli.Commands/Tool/ShowConfig/ShowConfigCommand.cs @@ -0,0 +1,35 @@ +using CreativeCoders.Cli.Core; +using CreativeCoders.Core.SysEnvironment; +using CreativeCoders.Git.Abstractions; +using CreativeCoders.GitTool.Base.Configurations; +using CreativeCoders.SysConsole.Core; +using Spectre.Console; + +namespace CreativeCoders.GitTool.Cli.Commands.Tool.ShowConfig; + +[CliCommand(["showconfig"], Description = "Shows the current repository configuration")] +public class ShowConfigCommand( + IAnsiConsole ansiConsole, + IRepositoryConfigurations repositoryConfigurations, + IGitRepositoryFactory gitRepositoryFactory) : ICliCommand +{ + public Task ExecuteAsync() + { + using var repository = gitRepositoryFactory.OpenRepository(Env.CurrentDirectory); + + var configuration = repositoryConfigurations.GetConfiguration(repository); + + ansiConsole.PrintBlock() + .WriteLine() + .WriteLine($"Configuration for '{repository.Info.RemoteUri}'") + .WriteLine() + .WriteLine($"HasDevelopBranch: {configuration.HasDevelopBranch}") + .WriteLine($"DevelopBranch: {configuration.DevelopBranch}") + .WriteLine($"FeatureBranchPrefix: {configuration.FeatureBranchPrefix}") + .WriteLine($"GitServiceProviderName: {configuration.GitServiceProviderName}") + .WriteLine($"DisableCertificateValidation: {configuration.DisableCertificateValidation}") + .WriteLine(); + + return Task.FromResult(CommandResult.Success); + } +} diff --git a/source/GitTool/CreativeCoders.GitTool.Cli.GtApp/CreativeCoders.GitTool.Cli.GtApp.csproj b/source/GitTool/CreativeCoders.GitTool.Cli.GtApp/CreativeCoders.GitTool.Cli.GtApp.csproj new file mode 100644 index 0000000..f536ad2 --- /dev/null +++ b/source/GitTool/CreativeCoders.GitTool.Cli.GtApp/CreativeCoders.GitTool.Cli.GtApp.csproj @@ -0,0 +1,24 @@ + + + + Exe + net10.0 + enable + enable + gt + CreativeCoders.GitTool.Cli.App + + + + + + + + + + + + + + + diff --git a/source/GitTool/CreativeCoders.GitTool.Cli.GtApp/Program.cs b/source/GitTool/CreativeCoders.GitTool.Cli.GtApp/Program.cs new file mode 100644 index 0000000..9aa4b72 --- /dev/null +++ b/source/GitTool/CreativeCoders.GitTool.Cli.GtApp/Program.cs @@ -0,0 +1,103 @@ +using CreativeCoders.Cli.Hosting; +using CreativeCoders.Cli.Hosting.Help; +using CreativeCoders.Core.IO; +using CreativeCoders.Core.SysEnvironment; +using CreativeCoders.Git.Abstractions; +using CreativeCoders.GitTool.Base; +using CreativeCoders.GitTool.Base.Configurations; +using CreativeCoders.GitTool.Base.Output; +using CreativeCoders.GitTool.Cli.Commands.FeatureGroup; +using CreativeCoders.GitTool.Cli.Commands.Shared; +using CreativeCoders.GitTool.Cli.Commands.Tool; +using CreativeCoders.GitTool.Cli.Commands.Tool.ShowConfig; +using CreativeCoders.GitTool.GitHub; +using CreativeCoders.GitTool.GitLab; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.DependencyInjection.Extensions; + +namespace CreativeCoders.GitTool.Cli.App; + +internal static class Program +{ + internal static async Task Main(string[] args) + { + var result = await CliHostBuilder.Create() + .ConfigureServices(ConfigureServices) + .EnableHelp(HelpCommandKind.CommandOrArgument) + .ScanAssemblies(typeof(ShowConfigCommand).Assembly) + .Build() + .RunAsync(args).ConfigureAwait(false); + + return result.ExitCode; + } + + private static void ConfigureServices(IServiceCollection services) + { + var configuration = AddConfiguration(services); + + services.AddOptions(); + + services.Configure(configuration.GetSection("tool")); + + ConfigureGitRepository(services); + + services.AddGitFeatureCommands(); + + services.AddGitSharedCommands(); + + services.AddGitTools(); + services.AddGitHubTools(configuration); + services.AddGitLabTools(configuration); + + services.AddSingleton(); + + services.AddSysConsole(); + } + + private static void ConfigureGitRepository(IServiceCollection services) + { + services.TryAddSingleton(sp => + { + var gitRepository = sp.GetRequiredService().OpenRepositoryFromCurrentDir(); + + var repositoryConfigurations = sp.GetRequiredService(); + + var repoConfiguration = repositoryConfigurations.GetConfiguration(gitRepository); + + if (repoConfiguration.DisableCertificateValidation) + { + gitRepository.CertificateCheck = (_, args) => + { + args.IsValid = true; + return true; + }; + } + + return gitRepository; + }); + } + + + private static IConfiguration AddConfiguration(IServiceCollection services) + { + var configurationBuilder = new ConfigurationBuilder(); + + var toolConfigurationFile = FileSys.Path.Combine( + Env.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), + GitToolApp.ConfigFolderName, + GitToolApp.ConfigFileName); + + if (FileSys.File.Exists(toolConfigurationFile)) + { + configurationBuilder.AddJsonFile(toolConfigurationFile); + } + + var configuration = configurationBuilder.Build(); + + services.AddSingleton(configuration); + services.AddSingleton(configuration); + + return configuration; + } +} diff --git a/source/GitTool/CreativeCoders.GitTool.Cli/CreativeCoders.GitTool.Cli.csproj b/source/GitTool/CreativeCoders.GitTool.Cli/CreativeCoders.GitTool.Cli.csproj deleted file mode 100644 index 48c184c..0000000 --- a/source/GitTool/CreativeCoders.GitTool.Cli/CreativeCoders.GitTool.Cli.csproj +++ /dev/null @@ -1,27 +0,0 @@ - - - - Exe - gt - enable - win-x64;linux-x64;linux-arm - - - - - - - - - - - - - - - - - - - - diff --git a/source/GitTool/CreativeCoders.GitTool.Cli/GitToolsExceptionMiddleware.cs b/source/GitTool/CreativeCoders.GitTool.Cli/GitToolsExceptionMiddleware.cs deleted file mode 100644 index 579d5e1..0000000 --- a/source/GitTool/CreativeCoders.GitTool.Cli/GitToolsExceptionMiddleware.cs +++ /dev/null @@ -1,52 +0,0 @@ -using System; -using System.Threading.Tasks; -using CreativeCoders.Core; -using CreativeCoders.Core.Collections; -using CreativeCoders.GitTool.Base.Output; -using CreativeCoders.SysConsole.Cli.Actions.Exceptions; -using CreativeCoders.SysConsole.Cli.Actions.Runtime; -using CreativeCoders.SysConsole.Cli.Actions.Runtime.Middleware; -using JetBrains.Annotations; -using Spectre.Console; - -namespace CreativeCoders.GitTool.Cli; - -[UsedImplicitly] -public class GitToolsExceptionMiddleware : CliActionMiddlewareBase -{ - private readonly IAnsiConsole _ansiConsole; - - private readonly ICml _cml; - - public GitToolsExceptionMiddleware(Func next, - IAnsiConsole ansiConsole, ICml cml) - : base(next) - { - _cml = Ensure.NotNull(cml); - _ansiConsole = Ensure.NotNull(ansiConsole); - } - - public override async Task InvokeAsync(CliActionContext context) - { - try - { - await Next(context); - } - catch (AmbiguousRouteException e) - { - _ansiConsole.WriteMarkupLine(_cml.Error($"Unknown command '{string.Join(' ', e.Arguments)}'")); - - e.Routes.ForEach(x => _ansiConsole.WriteMarkupLine(string.Join(' ', x.RouteParts))); - } - catch (Exception e) - { - _ansiConsole - .WriteMarkupLine(_cml.Error("An error occurred:")) - .WriteLineEx(e.ToString()) - .WriteMarkupLine(e.GetBaseException().Message) - .WriteLine(); - - context.ReturnCode = -1024; - } - } -} diff --git a/source/GitTool/CreativeCoders.GitTool.Cli/Program.cs b/source/GitTool/CreativeCoders.GitTool.Cli/Program.cs deleted file mode 100644 index b0efba5..0000000 --- a/source/GitTool/CreativeCoders.GitTool.Cli/Program.cs +++ /dev/null @@ -1,37 +0,0 @@ -using System; -using System.Threading.Tasks; -using CreativeCoders.Core.IO; -using CreativeCoders.Core.SysEnvironment; -using CreativeCoders.GitTool.Base; -using CreativeCoders.SysConsole.App; -using CreativeCoders.SysConsole.Cli.Actions; -using Microsoft.Extensions.Configuration; - -namespace CreativeCoders.GitTool.Cli; - -public static class Program -{ - public static async Task Main(string[] args) - { - return await BuildApp(args).RunAsync(); - } - - private static IConsoleApp BuildApp(string[] args) - { - return new ConsoleAppBuilder(args) - .UseActions() - .UseConfiguration(x => - { - var toolConfigurationFile = FileSys.Path.Combine( - Env.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), - GitToolApp.ConfigFolderName, - GitToolApp.ConfigFileName); - - if (FileSys.File.Exists(toolConfigurationFile)) - { - x.AddJsonFile(toolConfigurationFile); - } - }) - .Build(); - } -} diff --git a/source/GitTool/CreativeCoders.GitTool.Cli/Startup.cs b/source/GitTool/CreativeCoders.GitTool.Cli/Startup.cs deleted file mode 100644 index 9f70834..0000000 --- a/source/GitTool/CreativeCoders.GitTool.Cli/Startup.cs +++ /dev/null @@ -1,53 +0,0 @@ -using CreativeCoders.GitTool.Base.Configurations; -using CreativeCoders.GitTool.Base.Output; -using CreativeCoders.GitTool.Commands.Branches; -using CreativeCoders.GitTool.Commands.Features; -using CreativeCoders.GitTool.Commands.Releases; -using CreativeCoders.GitTool.Commands.Shared; -using CreativeCoders.GitTool.Commands.Tool; -using CreativeCoders.GitTool.GitHub; -using CreativeCoders.GitTool.GitLab; -using CreativeCoders.SysConsole.Cli.Actions; -using CreativeCoders.SysConsole.Cli.Actions.Runtime; -using CreativeCoders.SysConsole.Cli.Actions.Runtime.Middleware; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.DependencyInjection; -using Spectre.Console; - -namespace CreativeCoders.GitTool.Cli; - -public class Startup : ICliStartup -{ - public void ConfigureServices(IServiceCollection services, IConfiguration configuration) - { - services.AddOptions(); - - services.Configure(configuration.GetSection("tool")); - - services.AddGitFeatureCommands(); - - services.AddGitSharedCommands(); - - services.AddGitTools(); - services.AddGitHubTools(configuration); - services.AddGitLabTools(configuration); - - services.AddSingleton(_ => AnsiConsole.Create(new AnsiConsoleSettings())); - - services.AddSingleton(); - } - - public void Configure(ICliActionRuntimeBuilder runtimeBuilder) - { - runtimeBuilder.AddController(); - runtimeBuilder.AddController(); - runtimeBuilder.AddController(); - runtimeBuilder.AddController(); - - runtimeBuilder.UseMiddleware(); - - runtimeBuilder.UseHelp(); - - runtimeBuilder.UseRouting(); - } -} diff --git a/source/GitTool/CreativeCoders.GitTool.GitHub/CreativeCoders.GitTool.GitHub.csproj b/source/GitTool/CreativeCoders.GitTool.GitHub/CreativeCoders.GitTool.GitHub.csproj index 44e8b9b..950c8fc 100644 --- a/source/GitTool/CreativeCoders.GitTool.GitHub/CreativeCoders.GitTool.GitHub.csproj +++ b/source/GitTool/CreativeCoders.GitTool.GitHub/CreativeCoders.GitTool.GitHub.csproj @@ -5,10 +5,10 @@ - - - - + + + + diff --git a/tests/CreativeCoders.Git.Auth.CredentialManagerCore.UnitTests/CreativeCoders.Git.Auth.CredentialManagerCore.UnitTests.csproj b/tests/CreativeCoders.Git.Auth.CredentialManagerCore.UnitTests/CreativeCoders.Git.Auth.CredentialManagerCore.UnitTests.csproj index bf52214..9c75280 100644 --- a/tests/CreativeCoders.Git.Auth.CredentialManagerCore.UnitTests/CreativeCoders.Git.Auth.CredentialManagerCore.UnitTests.csproj +++ b/tests/CreativeCoders.Git.Auth.CredentialManagerCore.UnitTests/CreativeCoders.Git.Auth.CredentialManagerCore.UnitTests.csproj @@ -5,11 +5,11 @@ - - - - - + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive all @@ -22,7 +22,7 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - + diff --git a/tests/CreativeCoders.Git.UnitTests/CreativeCoders.Git.UnitTests.csproj b/tests/CreativeCoders.Git.UnitTests/CreativeCoders.Git.UnitTests.csproj index e650d62..b25d634 100644 --- a/tests/CreativeCoders.Git.UnitTests/CreativeCoders.Git.UnitTests.csproj +++ b/tests/CreativeCoders.Git.UnitTests/CreativeCoders.Git.UnitTests.csproj @@ -5,10 +5,10 @@ - - - - + + + + runtime; build; native; contentfiles; analyzers; buildtransitive all @@ -21,7 +21,7 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - + diff --git a/tests/CreativeCoders.GitTool.GitHub.UnitTests/CreativeCoders.GitTool.GitHub.UnitTests.csproj b/tests/CreativeCoders.GitTool.GitHub.UnitTests/CreativeCoders.GitTool.GitHub.UnitTests.csproj index 7f16420..2061174 100644 --- a/tests/CreativeCoders.GitTool.GitHub.UnitTests/CreativeCoders.GitTool.GitHub.UnitTests.csproj +++ b/tests/CreativeCoders.GitTool.GitHub.UnitTests/CreativeCoders.GitTool.GitHub.UnitTests.csproj @@ -5,10 +5,10 @@ - - - - + + + + runtime; build; native; contentfiles; analyzers; buildtransitive all @@ -21,7 +21,7 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - + diff --git a/tests/CreativeCoders.GitTool.GitLab.UnitTests/CreativeCoders.GitTool.GitLab.UnitTests.csproj b/tests/CreativeCoders.GitTool.GitLab.UnitTests/CreativeCoders.GitTool.GitLab.UnitTests.csproj index 11971b2..e642bc3 100644 --- a/tests/CreativeCoders.GitTool.GitLab.UnitTests/CreativeCoders.GitTool.GitLab.UnitTests.csproj +++ b/tests/CreativeCoders.GitTool.GitLab.UnitTests/CreativeCoders.GitTool.GitLab.UnitTests.csproj @@ -5,10 +5,10 @@ - - - - + + + + runtime; build; native; contentfiles; analyzers; buildtransitive all @@ -21,7 +21,7 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - +