Merge pull request #5198 from abpframework/issue-3140

Cli: Suite install & update improvements
pull/5251/head
Alper Ebicoglu 5 years ago committed by GitHub
commit 06e4e5ea3e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1,10 +1,13 @@
using System;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using NuGet.Versioning;
using Volo.Abp.Cli.Args;
using Volo.Abp.Cli.Commands.Services;
using Volo.Abp.Cli.NuGet;
using Volo.Abp.Cli.Utils;
using Volo.Abp.DependencyInjection;
@ -13,12 +16,14 @@ namespace Volo.Abp.Cli.Commands
public class SuiteCommand : IConsoleCommand, ITransientDependency
{
private readonly AbpNuGetIndexUrlService _nuGetIndexUrlService;
private readonly NuGetService _nuGetService;
private const string SuitePackageName = "Volo.Abp.Suite";
public ILogger<SuiteCommand> Logger { get; set; }
public SuiteCommand(AbpNuGetIndexUrlService nuGetIndexUrlService)
public SuiteCommand(AbpNuGetIndexUrlService nuGetIndexUrlService, NuGetService nuGetService)
{
_nuGetIndexUrlService = nuGetIndexUrlService;
_nuGetService = nuGetService;
Logger = NullLogger<SuiteCommand>.Instance;
}
@ -26,21 +31,22 @@ namespace Volo.Abp.Cli.Commands
{
var operationType = NamespaceHelper.NormalizeNamespace(commandLineArgs.Target);
var preview = commandLineArgs.Options.ContainsKey(Options.Preview.Long);
switch (operationType)
{
case "":
case null:
await InstallSuiteIfNotInstalledAsync();
RunSuite();
break;
case "install":
Logger.LogInformation("Installing ABP Suite...");
await InstallSuiteAsync();
await InstallSuiteAsync(preview);
break;
case "update":
Logger.LogInformation("Updating ABP Suite...");
await UpdateSuiteAsync();
await UpdateSuiteAsync(preview);
break;
case "remove":
@ -50,8 +56,34 @@ namespace Volo.Abp.Cli.Commands
}
}
private async Task InstallSuiteAsync()
private async Task InstallSuiteIfNotInstalledAsync()
{
var currentSuiteVersionAsString = GetCurrentSuiteVersion();
if (string.IsNullOrEmpty(currentSuiteVersionAsString))
{
await InstallSuiteAsync();
}
}
private string GetCurrentSuiteVersion()
{
var dotnetToolList = CmdHelper.RunCmdAndGetOutput("dotnet tool list -g");
var suiteLine = dotnetToolList.Split(Environment.NewLine).FirstOrDefault(l => l.ToLower().StartsWith("volo.abp.suite "));
if (string.IsNullOrEmpty(suiteLine))
{
return null;
}
return suiteLine.Split(" ", StringSplitOptions.RemoveEmptyEntries)[1];
}
private async Task InstallSuiteAsync(bool preview = false)
{
Logger.LogInformation("Installing ABP Suite...");
var nugetIndexUrl = await _nuGetIndexUrlService.GetAsync();
if (nugetIndexUrl == null)
@ -61,7 +93,9 @@ namespace Volo.Abp.Cli.Commands
try
{
var result = CmdHelper.RunCmd("dotnet tool install " + SuitePackageName + " --add-source " + nugetIndexUrl + " -g");
var versionOption = await GetVersionOption(preview);
var result = CmdHelper.RunCmd($"dotnet tool install {SuitePackageName} {versionOption} --add-source {nugetIndexUrl} -g");
if (result == 0)
{
@ -86,8 +120,10 @@ namespace Volo.Abp.Cli.Commands
Logger.LogInformation("dotnet tool install -g Volo.Abp.Suite");
}
private async Task UpdateSuiteAsync()
private async Task UpdateSuiteAsync(bool preview = false)
{
Logger.LogInformation("Updating ABP Suite...");
var nugetIndexUrl = await _nuGetIndexUrlService.GetAsync();
if (nugetIndexUrl == null)
@ -97,7 +133,9 @@ namespace Volo.Abp.Cli.Commands
try
{
var result = CmdHelper.RunCmd("dotnet tool update " + SuitePackageName + " --add-source " + nugetIndexUrl + " -g");
var versionOption = await GetVersionOption(preview);
var result = CmdHelper.RunCmd($"dotnet tool update {SuitePackageName} {versionOption} --add-source {nugetIndexUrl} -g");
if (result != 0)
{
@ -111,6 +149,25 @@ namespace Volo.Abp.Cli.Commands
}
}
private async Task<string> GetVersionOption(bool preview)
{
if (preview)
{
var latestVersion = await GetLatestSuiteVersioAsync(true);
if (latestVersion.IsPrerelease)
{
return $"--version {latestVersion.ToString()}";
}
}
return "";
}
private async Task<SemanticVersion> GetLatestSuiteVersioAsync(bool preview)
{
return await _nuGetService.GetLatestVersionOrNullAsync(SuitePackageName, includeReleaseCandidates: preview);
}
private void ShowSuiteManualUpdateCommand()
{
Logger.LogError("You can also run the following command to update ABP Suite.");
@ -160,7 +217,9 @@ namespace Volo.Abp.Cli.Commands
sb.AppendLine("");
sb.AppendLine(" abp suite");
sb.AppendLine(" abp suite install");
sb.AppendLine(" abp suite install --preview");
sb.AppendLine(" abp suite update");
sb.AppendLine(" abp suite update --preview");
sb.AppendLine(" abp suite remove");
sb.AppendLine("");
@ -171,5 +230,13 @@ namespace Volo.Abp.Cli.Commands
{
return "Install, update, remove or start ABP Suite. See https://commercial.abp.io/tools/suite.";
}
public static class Options
{
public static class Preview
{
public const string Long = "preview";
}
}
}
}
}

Loading…
Cancel
Save