Browse Source

Add `delaySeconds` paramter to CmdHelper.

pull/12920/head
maliming 4 years ago
parent
commit
d42f027d79
No known key found for this signature in database GPG Key ID: 96224957E51C89E
  1. 13
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/CliCommand.cs
  2. 25
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Utils/CmdHelper.cs
  3. 8
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Utils/ICmdHelper.cs

13
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/CliCommand.cs

@ -59,7 +59,6 @@ public class CliCommand : IConsoleCommand, ITransientDependency
private async Task UpdateCliAsync(string version = null, bool preview = false)
{
RemoveCli();
var infoText = "Updating ABP CLI ";
if (version != null)
{
@ -94,15 +93,7 @@ public class CliCommand : IConsoleCommand, ITransientDependency
versionOption = $" --version {version}";
}
_cmdHelper.RunCmd(
$"dotnet tool update {CliPackageName}{versionOption} -g",
out var exitCode
);
if (exitCode != 0)
{
ShowCliManualUpdateCommand();
}
_cmdHelper.RunCmdAndExit($"dotnet tool update {CliPackageName}{versionOption} -g", delaySeconds: 2);
}
catch (Exception ex)
{
@ -131,7 +122,7 @@ public class CliCommand : IConsoleCommand, ITransientDependency
private void RemoveCli()
{
Logger.LogInformation("Removing CLI...");
_cmdHelper.RunCmd("dotnet tool uninstall " + CliPackageName + " -g");
_cmdHelper.RunCmdAndExit("dotnet tool uninstall " + CliPackageName + " -g", delaySeconds: 2);
}
public string GetUsageInfo()

25
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Utils/CmdHelper.cs

@ -1,4 +1,5 @@
using System.Diagnostics;
using System;
using System.Diagnostics;
using System.IO;
using System.Runtime.InteropServices;
using Volo.Abp.DependencyInjection;
@ -125,15 +126,31 @@ public class CmdHelper : ICmdHelper, ITransientDependency
return output.Trim();
}
public string GetArguments(string command)
public void RunCmdAndExit(string command, string workingDirectory = null, int? delaySeconds = null)
{
var procStartInfo = new ProcessStartInfo(
GetFileName(),
GetArguments(command, delaySeconds)
);
if (!string.IsNullOrEmpty(workingDirectory))
{
procStartInfo.WorkingDirectory = workingDirectory;
}
Process.Start(procStartInfo);
Environment.Exit(0);
}
public string GetArguments(string command, int? delaySeconds = null)
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX) || RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
return "-c \"" + command + "\"";
return delaySeconds == null ? "-c \"" + command + "\"" : "-c \"" + $"sleep {delaySeconds}s > /dev/null && " + command + "\"";
}
//Windows default.
return "/C \"" + command + "\"";
return delaySeconds == null ? "/C \"" + command + "\"" : "/C \"" + $"timeout /nobreak /t {delaySeconds} >null && " + command + "\"";
}
public string GetFileName()

8
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Utils/ICmdHelper.cs

@ -8,20 +8,22 @@ public interface ICmdHelper
void Run(string file, string arguments);
string GetArguments(string command);
string GetArguments(string command, int? delaySeconds = null);
string GetFileName();
void RunCmd(string command, string workingDirectory = null);
Process RunCmdAndGetProcess(string command, string workingDirectory = null);
void RunCmd(string command, out int exitCode, string workingDirectory = null);
string RunCmdAndGetOutput(string command, string workingDirectory = null);
string RunCmdAndGetOutput(string command, out bool isExitCodeSuccessful, string workingDirectory = null);
string RunCmdAndGetOutput(string command, out int exitCode, string workingDirectory = null);
void RunCmdAndExit(string command, string workingDirectory = null, int? delaySeconds = null);
}

Loading…
Cancel
Save