add suite cli command.

rel-1.1
Alper Ebicoglu 6 years ago
parent f8ea908112
commit def70c5fe0

@ -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<string> 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 <username>\"."
: "You are not signed in to commercial.abp.io. Use the CLI command \"abp login <username>\" 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.";
}
}
}

@ -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";
}
}
}

@ -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
/// <param name="toolCommandName">Eg: For AbpSuite tool it's "abp-suite", for ABP CLI tool it's "abp"</param>
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);
}
}
}
Loading…
Cancel
Save