From def70c5fe02d5e8139e55de5614942f025dd3761 Mon Sep 17 00:00:00 2001 From: Alper Ebicoglu Date: Thu, 12 Dec 2019 12:43:29 +0300 Subject: [PATCH] add suite cli command. --- .../Volo/Abp/Cli/Commands/SuiteCommand.cs | 42 +++++++++++++------ .../Volo/Abp/Cli/Utils/CmdHelper.cs | 8 ++-- .../Volo/Abp/Cli/Utils/GlobalToolHelper.cs | 19 +++++++-- 3 files changed, 50 insertions(+), 19 deletions(-) diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/SuiteCommand.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/SuiteCommand.cs index a7c767ffc6..dd811c7092 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/SuiteCommand.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/SuiteCommand.cs @@ -36,7 +36,7 @@ namespace Volo.Abp.Cli.Commands switch (operationType) { case "": - Logger.LogInformation("Running Suite..."); + case null: RunSuite(); break; @@ -49,7 +49,7 @@ namespace Volo.Abp.Cli.Commands case "update": case "u": Logger.LogInformation("Updating Suite..."); - UpdateSuite(); + await UpdateSuiteAsync(); break; case "remove": @@ -62,21 +62,20 @@ namespace Volo.Abp.Cli.Commands private async Task InstallSuiteAsync() { - var apiKeyResult = await _apiKeyService.GetApiKeyOrNullAsync(); - if (apiKeyResult == null || string.IsNullOrEmpty(apiKeyResult.ApiKey)) + var nugetIndexUrl = await GetNuGetIndexUrlAsync(); + var result = CmdHelper.RunCmd("dotnet tool install " + SuitePackageName + " --add-source " + nugetIndexUrl + " -g"); + + if (result == 0) { - Logger.LogInformation("Couldn't retrieve the API Key for Nuget!"); - await Task.CompletedTask; - return; + Logger.LogInformation("Suite has been successfully installed."); + Logger.LogInformation("You can run it with the CLI command \"abp suite\""); } - - var nugetIndexUrl = CliUrls.GetNuGetServiceIndexUrl(apiKeyResult.ApiKey); - CmdHelper.RunCmd("dotnet tool install " + SuitePackageName + " --add-source " + nugetIndexUrl + " -g"); } - private static void UpdateSuite() + private async Task UpdateSuiteAsync() { - CmdHelper.RunCmd("dotnet tool update " + SuitePackageName + " -g"); + var nugetIndexUrl = await GetNuGetIndexUrlAsync(); + CmdHelper.RunCmd("dotnet tool update " + SuitePackageName + " --add-source " + nugetIndexUrl + " -g"); } private static void RemoveSuite() @@ -102,6 +101,23 @@ namespace Volo.Abp.Cli.Commands CmdHelper.RunCmd("abp-suite"); } + private async Task GetNuGetIndexUrlAsync() + { + var apiKeyResult = await _apiKeyService.GetApiKeyOrNullAsync(); + if (apiKeyResult == null || + string.IsNullOrEmpty(apiKeyResult.ApiKey)) + { + Logger.LogError("Couldn't retrieve your NuGet API key!"); + Logger.LogWarning(File.Exists(CliPaths.AccessToken) + ? "Make sure you have an active session and license on commercial.abp.io. To re-sign in you can use the CLI command \"abp login \"." + : "You are not signed in to commercial.abp.io. Use the CLI command \"abp login \" to sign in."); + + return null; + } + + return CliUrls.GetNuGetServiceIndexUrl(apiKeyResult.ApiKey); + } + public string GetUsageInfo() { var sb = new StringBuilder(); @@ -130,7 +146,7 @@ namespace Volo.Abp.Cli.Commands public string GetShortDescription() { - return "Shortcut commands to use Abp Suite tool."; + return "Utility commands to use Abp Suite tool. Installs, updates, removes or starts Suite."; } } } \ No newline at end of file diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Utils/CmdHelper.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Utils/CmdHelper.cs index 0c7c9fc6c0..b871c295f6 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Utils/CmdHelper.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Utils/CmdHelper.cs @@ -11,10 +11,12 @@ namespace Volo.Abp.Cli.Utils Process.Start(procStartInfo).WaitForExit(); } - public static void RunCmd(string command) + public static int RunCmd(string command) { var procStartInfo = new ProcessStartInfo(GetFileName(), GetArguments(command)); - Process.Start(procStartInfo).WaitForExit(); + var process = Process.Start(procStartInfo); + process?.WaitForExit(); + return process?.ExitCode ?? 0; } public static string RunCmdAndGetOutput(string command) @@ -66,7 +68,7 @@ namespace Volo.Abp.Cli.Utils } //Windows default. - return "cmd.exe"; + return "cmd.exe"; } } } diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Utils/GlobalToolHelper.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Utils/GlobalToolHelper.cs index 325d73a99b..8424262324 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Utils/GlobalToolHelper.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Utils/GlobalToolHelper.cs @@ -1,4 +1,5 @@ -using System.IO; +using System; +using System.IO; namespace Volo.Abp.Cli.Utils { @@ -10,12 +11,24 @@ namespace Volo.Abp.Cli.Utils /// Eg: For AbpSuite tool it's "abp-suite", for ABP CLI tool it's "abp" public static bool IsGlobalToolInstalled(string toolCommandName) { + string suitePath; + if (PlatformHelper.GetPlatform() == RuntimePlatform.LinuxOrMacOs) { - return File.Exists("%HOME%/.dotnet/tools/" + toolCommandName); + suitePath = Environment + .ExpandEnvironmentVariables( + Path.Combine("%HOME%", ".dotnet", "tools", toolCommandName) + ); + } + else + { + suitePath = Environment + .ExpandEnvironmentVariables( + Path.Combine(@"%USERPROFILE%", ".dotnet", "tools", toolCommandName + ".exe") + ); } - return File.Exists(@"%USERPROFILE%\.dotnet\tools\" + toolCommandName + ".exe"); + return File.Exists(suitePath); } } } \ No newline at end of file