chore: small refactorings

This commit is contained in:
Matthias Langhard
2021-11-02 20:25:02 +01:00
parent 0ede69ccc4
commit 38c94e315f

View File

@@ -20,6 +20,15 @@ namespace Cli
}
public async Task Run(string workingDir)
{
var repoBasePath = await GetRepoBasePath(workingDir);
var chosenService = await ChooseService(repoBasePath);
var selection = await SelectVersion(repoBasePath, chosenService);
await AddVersionTagToRepo(repoBasePath, selection.Version.ToString());
await PushToRemote(repoBasePath);
}
private async Task<string> GetRepoBasePath(string workingDir)
{
var repoBasePath = "";
try
@@ -32,6 +41,11 @@ namespace Cli
Environment.Exit(1);
}
return repoBasePath;
}
private async Task<string> ChooseService(string repoBasePath)
{
var services = new List<string>();
try
{
@@ -54,7 +68,11 @@ namespace Cli
.AddChoices(services));
}
return chosenService;
}
private async Task<Selection> SelectVersion(string repoBasePath, string chosenService)
{
var versionInfo = await _mediator.Send(new GetVersionInformationFromRepo.Query(repoBasePath, chosenService));
Selection selection;
if (versionInfo != null)
@@ -90,17 +108,11 @@ namespace Cli
Environment.Exit(0);
}
try
{
await _mediator.Send(new AddTagToGitRepo.Command(workingDir, selection.Version.ToString()));
}
catch (Exception ex)
{
AnsiConsole.Markup("[red]Error:[/] Unable to write Tag to repository\n\n");
AnsiConsole.WriteException(ex);
Environment.Exit(1);
}
return selection;
}
private async Task PushToRemote(string workingDir)
{
try
{
await _mediator.Send(new PushCommitsToRemote.Command(workingDir));
@@ -112,5 +124,19 @@ namespace Cli
Environment.Exit(1);
}
}
private async Task AddVersionTagToRepo(string workingDir, string tag)
{
try
{
await _mediator.Send(new AddTagToGitRepo.Command(workingDir, tag));
}
catch (Exception ex)
{
AnsiConsole.Markup("[red]Error:[/] Unable to write Tag to repository\n\n");
AnsiConsole.WriteException(ex);
Environment.Exit(1);
}
}
}
}