Browse Source

Moved ICmdHelper to CLI.Core

pull/10363/head
Yunus Emre Kalkan 5 years ago
parent
commit
a6477782b1
  1. 7
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Build/DefaultDotNetProjectBuilder.cs
  2. 11
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/CliService.cs
  3. 12
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/CreateMigrationAndRunMigratorCommand.cs
  4. 6
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/GenerateProxyCommand.cs
  5. 5
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/NewCommand.cs
  6. 4
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/ProjectCreationCommandBase.cs
  7. 4
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/ProxyCommandBase.cs
  8. 10
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/RemoveProxyCommand.cs
  9. 22
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/SuiteCommand.cs
  10. 4
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/LIbs/InstallLibsService.cs
  11. 4
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/EfCoreMigrationManager.cs
  12. 6
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/NpmGlobalPackagesChecker.cs
  13. 5
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/NpmPackagesUpdater.cs
  14. 7
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/ProjectNpmPackageAdder.cs
  15. 5
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/ProjectNugetPackageAdder.cs
  16. 7
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/SolutionModuleAdder.cs
  17. 46
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Utils/CmdHelper.cs
  18. 24
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Utils/ICmdHelper.cs
  19. 103
      studio/src/Volo.Abp.Studio.Domain.CommonServices/Volo/Abp/Studio/Helpers/CmdHelper.cs
  20. 9
      studio/src/Volo.Abp.Studio.Domain.CommonServices/Volo/Abp/Studio/Helpers/ICmdHelper.cs
  21. 1
      studio/src/Volo.Abp.Studio.Domain.CommonServices/Volo/Abp/Studio/Nuget/NugetPackageCacheManager.cs
  22. 1
      studio/src/Volo.Abp.Studio.Domain.CommonServices/Volo/Abp/Studio/Nuget/NugetSourceCodeStore.cs

7
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Build/DefaultDotNetProjectBuilder.cs

@ -9,6 +9,13 @@ namespace Volo.Abp.Cli.Build
{
public class DefaultDotNetProjectBuilder : IDotNetProjectBuilder, ITransientDependency
{
public ICmdHelper CmdHelper { get; }
public DefaultDotNetProjectBuilder(ICmdHelper cmdHelper)
{
CmdHelper = cmdHelper;
}
public List<string> BuildProjects(List<DotNetProjectInfo> projects, string arguments)
{
var builtProjects = new ConcurrentBag<string>();

11
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/CliService.cs

@ -24,17 +24,20 @@ namespace Volo.Abp.Cli
protected ICommandSelector CommandSelector { get; }
protected IServiceScopeFactory ServiceScopeFactory { get; }
protected NuGetService NuGetService { get; }
public ICmdHelper CmdHelper { get; }
public CliService(
ICommandLineArgumentParser commandLineArgumentParser,
ICommandSelector commandSelector,
IServiceScopeFactory serviceScopeFactory,
NuGetService nugetService)
NuGetService nugetService,
ICmdHelper cmdHelper)
{
CommandLineArgumentParser = commandLineArgumentParser;
CommandSelector = commandSelector;
ServiceScopeFactory = serviceScopeFactory;
NuGetService = nugetService;
CmdHelper = cmdHelper;
Logger = NullLogger<CliService>.Instance;
}
@ -42,7 +45,7 @@ namespace Volo.Abp.Cli
public async Task RunAsync(string[] args)
{
Logger.LogInformation("ABP CLI (https://abp.io)");
var commandLineArgs = CommandLineArgumentParser.Parse(args);
#if !DEBUG
@ -147,7 +150,7 @@ namespace Volo.Abp.Cli
await RunInternalAsync(args);
}
}
private async Task RunInternalAsync(CommandLineArgs commandLineArgs)
{
var commandType = CommandSelector.Select(commandLineArgs);
@ -203,7 +206,7 @@ namespace Volo.Abp.Cli
{
SemanticVersion currentCliVersion = default;
var consoleOutput = new StringReader(CmdHelper.RunCmdAndGetOutput($"dotnet tool list -g"));
var consoleOutput = new StringReader(CmdHelper.RunCmdAndGetOutput($"dotnet tool list -g", out int exitCode));
string line;
while ((line = await consoleOutput.ReadLineAsync()) != null)
{

12
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/CreateMigrationAndRunMigratorCommand.cs

@ -12,10 +12,12 @@ namespace Volo.Abp.Cli.Commands
{
public class CreateMigrationAndRunMigratorCommand : IConsoleCommand, ITransientDependency
{
public ICmdHelper CmdHelper { get; }
public ILogger<CreateMigrationAndRunMigratorCommand> Logger { get; set; }
public CreateMigrationAndRunMigratorCommand()
public CreateMigrationAndRunMigratorCommand(ICmdHelper cmdHelper)
{
CmdHelper = cmdHelper;
Logger = NullLogger<CreateMigrationAndRunMigratorCommand>.Instance;
}
@ -98,7 +100,7 @@ namespace Volo.Abp.Cli.Commands
return Path.GetFileName(dbContext).RemovePostFix(".cs");
}
private static string AddMigrationAndGetOutput(string dbMigrationsFolder, string dbContext, string outputDirectory)
private string AddMigrationAndGetOutput(string dbMigrationsFolder, string dbContext, string outputDirectory)
{
var dbContextOption = string.IsNullOrWhiteSpace(dbContext)
? string.Empty
@ -107,12 +109,12 @@ namespace Volo.Abp.Cli.Commands
var addMigrationCmd = $"cd \"{dbMigrationsFolder}\" && " +
$"dotnet ef migrations add Initial --output-dir {outputDirectory} {dbContextOption}";
return CmdHelper.RunCmdAndGetOutput(addMigrationCmd);
return CmdHelper.RunCmdAndGetOutput(addMigrationCmd, out int exitCode);
}
private static bool IsDotNetEfToolInstalled()
private bool IsDotNetEfToolInstalled()
{
var output = CmdHelper.RunCmdAndGetOutput("dotnet tool list -g");
var output = CmdHelper.RunCmdAndGetOutput("dotnet tool list -g", out int exitCode);
return output.Contains("dotnet-ef");
}

6
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/GenerateProxyCommand.cs

@ -1,3 +1,5 @@
using Volo.Abp.Cli.Utils;
namespace Volo.Abp.Cli.Commands
{
public class GenerateProxyCommand : ProxyCommandBase
@ -8,8 +10,8 @@ namespace Volo.Abp.Cli.Commands
protected override string SchematicsCommandName => "proxy-add";
public GenerateProxyCommand(CliService cliService)
: base(cliService)
public GenerateProxyCommand(CliService cliService, ICmdHelper cmdHelper)
: base(cliService, cmdHelper)
{
}

5
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/NewCommand.cs

@ -35,8 +35,9 @@ namespace Volo.Abp.Cli.Commands
public NewCommand(TemplateProjectBuilder templateProjectBuilder
, ITemplateInfoProvider templateInfoProvider,
ConnectionStringProvider connectionStringProvider)
: base(connectionStringProvider)
ConnectionStringProvider connectionStringProvider,
ICmdHelper cmdHelper)
: base(connectionStringProvider, cmdHelper)
{
TemplateProjectBuilder = templateProjectBuilder;
TemplateInfoProvider = templateInfoProvider;

4
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/ProjectCreationCommandBase.cs

@ -18,11 +18,13 @@ namespace Volo.Abp.Cli.Commands
public abstract class ProjectCreationCommandBase
{
public ConnectionStringProvider ConnectionStringProvider { get; }
public ICmdHelper CmdHelper { get; }
public ILogger<NewCommand> Logger { get; set; }
public ProjectCreationCommandBase(ConnectionStringProvider connectionStringProvider)
public ProjectCreationCommandBase(ConnectionStringProvider connectionStringProvider, ICmdHelper cmdHelper)
{
ConnectionStringProvider = connectionStringProvider;
CmdHelper = cmdHelper;
Logger = NullLogger<NewCommand>.Instance;
}

4
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/ProxyCommandBase.cs

@ -15,15 +15,17 @@ namespace Volo.Abp.Cli.Commands
public abstract class ProxyCommandBase : IConsoleCommand, ITransientDependency
{
public CliService CliService { get; }
public ICmdHelper CmdHelper { get; }
public ILogger<HelpCommand> Logger { get; set; }
protected abstract string CommandName { get; }
protected abstract string SchematicsCommandName { get; }
public ProxyCommandBase(CliService cliService)
public ProxyCommandBase(CliService cliService, ICmdHelper cmdHelper)
{
CliService = cliService;
CmdHelper = cmdHelper;
Logger = NullLogger<HelpCommand>.Instance;
}

10
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/RemoveProxyCommand.cs

@ -1,4 +1,6 @@
namespace Volo.Abp.Cli.Commands
using Volo.Abp.Cli.Utils;
namespace Volo.Abp.Cli.Commands
{
public class RemoveProxyCommand : ProxyCommandBase
{
@ -8,8 +10,10 @@
protected override string SchematicsCommandName => "proxy-remove";
public RemoveProxyCommand(CliService cliService)
: base(cliService)
public RemoveProxyCommand(
CliService cliService,
ICmdHelper cmdHelper)
: base(cliService, cmdHelper)
{
}

22
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/SuiteCommand.cs

@ -15,13 +15,15 @@ namespace Volo.Abp.Cli.Commands
{
public class SuiteCommand : IConsoleCommand, ITransientDependency
{
public ICmdHelper CmdHelper { get; }
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, NuGetService nuGetService)
public SuiteCommand(AbpNuGetIndexUrlService nuGetIndexUrlService, NuGetService nuGetService, ICmdHelper cmdHelper)
{
CmdHelper = cmdHelper;
_nuGetIndexUrlService = nuGetIndexUrlService;
_nuGetService = nuGetService;
Logger = NullLogger<SuiteCommand>.Instance;
@ -71,7 +73,7 @@ namespace Volo.Abp.Cli.Commands
private string GetCurrentSuiteVersion()
{
var dotnetToolList = CmdHelper.RunCmdAndGetOutput("dotnet tool list -g");
var dotnetToolList = CmdHelper.RunCmdAndGetOutput("dotnet tool list -g", out int exitCode);
var suiteLine = dotnetToolList.Split(Environment.NewLine)
.FirstOrDefault(l => l.ToLower().StartsWith("volo.abp.suite "));
@ -127,11 +129,11 @@ namespace Volo.Abp.Cli.Commands
versionOption = $" --version {version}";
}
var result = CmdHelper.RunCmd(
$"dotnet tool install {SuitePackageName}{versionOption} --add-source {nugetIndexUrl} -g"
CmdHelper.RunCmd(
$"dotnet tool install {SuitePackageName}{versionOption} --add-source {nugetIndexUrl} -g", out int exitCode
);
if (result == 0)
if (exitCode == 0)
{
Logger.LogInformation("ABP Suite has been successfully installed.");
Logger.LogInformation("You can run it with the CLI command \"abp suite\"");
@ -197,11 +199,11 @@ namespace Volo.Abp.Cli.Commands
versionOption = $" --version {version}";
}
var result = CmdHelper.RunCmd(
$"dotnet tool update {SuitePackageName}{versionOption} --add-source {nugetIndexUrl} -g"
CmdHelper.RunCmd(
$"dotnet tool update {SuitePackageName}{versionOption} --add-source {nugetIndexUrl} -g", out int exitCode
);
if (result != 0)
if (exitCode != 0)
{
ShowSuiteManualUpdateCommand();
}
@ -230,7 +232,7 @@ namespace Volo.Abp.Cli.Commands
Logger.LogError("dotnet tool update -g Volo.Abp.Suite --add-source https://nuget.abp.io/<your-private-key>/v3/index.json");
}
private static void RemoveSuite()
private void RemoveSuite()
{
CmdHelper.RunCmd("dotnet tool uninstall " + SuitePackageName + " -g");
}
@ -275,7 +277,7 @@ namespace Volo.Abp.Cli.Commands
sb.AppendLine(" abp suite");
sb.AppendLine(" abp suite install");
sb.AppendLine(" abp suite install --preview");
sb.AppendLine(" abp suite install --version 4.2.2");
sb.AppendLine(" abp suite install --version 4.2.2");
sb.AppendLine(" abp suite update");
sb.AppendLine(" abp suite update --preview");
sb.AppendLine(" abp suite remove");

4
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/LIbs/InstallLibsService.cs

@ -16,14 +16,16 @@ namespace Volo.Abp.Cli.LIbs
{
public class InstallLibsService : IInstallLibsService, ITransientDependency
{
public ICmdHelper CmdHelper { get; }
public const string LibsDirectory = "./wwwroot/libs";
public ILogger<InstallLibsService> Logger { get; set; }
private readonly IJsonSerializer _jsonSerializer;
public InstallLibsService(IJsonSerializer jsonSerializer)
public InstallLibsService(IJsonSerializer jsonSerializer, ICmdHelper cmdHelper)
{
CmdHelper = cmdHelper;
_jsonSerializer = jsonSerializer;
Logger = NullLogger<InstallLibsService>.Instance;
}

4
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/EfCoreMigrationManager.cs

@ -10,10 +10,12 @@ namespace Volo.Abp.Cli.ProjectModification
{
public class EfCoreMigrationManager : ITransientDependency
{
public ICmdHelper CmdHelper { get; }
public ILogger<EfCoreMigrationManager> Logger { get; set; }
public EfCoreMigrationManager()
public EfCoreMigrationManager(ICmdHelper cmdHelper)
{
CmdHelper = cmdHelper;
Logger = NullLogger<EfCoreMigrationManager>.Instance;
}

6
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/NpmGlobalPackagesChecker.cs

@ -7,10 +7,12 @@ namespace Volo.Abp.Cli.ProjectModification
{
public class NpmGlobalPackagesChecker : ITransientDependency
{
public ICmdHelper CmdHelper { get; }
public ILogger<NpmGlobalPackagesChecker> Logger { get; set; }
public NpmGlobalPackagesChecker()
public NpmGlobalPackagesChecker(ICmdHelper cmdHelper)
{
CmdHelper = cmdHelper;
Logger = NullLogger<NpmGlobalPackagesChecker>.Instance;
}
@ -31,7 +33,7 @@ namespace Volo.Abp.Cli.ProjectModification
protected virtual string GetInstalledNpmPackages()
{
Logger.LogInformation("Checking installed npm global packages...");
return CmdHelper.RunCmdAndGetOutput("npm list -g --depth 0 --silent");
return CmdHelper.RunCmdAndGetOutput("npm list -g --depth 0 --silent", out int exitCode);
}
protected virtual void InstallYarn()

5
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/NpmPackagesUpdater.cs

@ -23,6 +23,7 @@ namespace Volo.Abp.Cli.ProjectModification
{
public ILogger<NpmPackagesUpdater> Logger { get; set; }
protected ICancellationTokenProvider CancellationTokenProvider { get; }
public ICmdHelper CmdHelper { get; }
private readonly PackageJsonFileFinder _packageJsonFileFinder;
private readonly NpmGlobalPackagesChecker _npmGlobalPackagesChecker;
@ -33,11 +34,13 @@ namespace Volo.Abp.Cli.ProjectModification
PackageJsonFileFinder packageJsonFileFinder,
NpmGlobalPackagesChecker npmGlobalPackagesChecker,
ICancellationTokenProvider cancellationTokenProvider,
CliHttpClientFactory cliHttpClientFactory)
CliHttpClientFactory cliHttpClientFactory,
ICmdHelper cmdHelper)
{
_packageJsonFileFinder = packageJsonFileFinder;
_npmGlobalPackagesChecker = npmGlobalPackagesChecker;
CancellationTokenProvider = cancellationTokenProvider;
CmdHelper = cmdHelper;
_cliHttpClientFactory = cliHttpClientFactory;
Logger = NullLogger<NpmPackagesUpdater>.Instance;
}

7
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/ProjectNpmPackageAdder.cs

@ -26,6 +26,7 @@ namespace Volo.Abp.Cli.ProjectModification
public SourceCodeDownloadService SourceCodeDownloadService { get; }
public AngularSourceCodeAdder AngularSourceCodeAdder { get; }
public IRemoteServiceExceptionHandler RemoteServiceExceptionHandler { get; }
public ICmdHelper CmdHelper { get; }
private readonly CliHttpClientFactory _cliHttpClientFactory;
public ILogger<ProjectNpmPackageAdder> Logger { get; set; }
@ -33,12 +34,14 @@ namespace Volo.Abp.Cli.ProjectModification
IJsonSerializer jsonSerializer,
SourceCodeDownloadService sourceCodeDownloadService,
AngularSourceCodeAdder angularSourceCodeAdder,
IRemoteServiceExceptionHandler remoteServiceExceptionHandler)
IRemoteServiceExceptionHandler remoteServiceExceptionHandler,
ICmdHelper cmdHelper)
{
JsonSerializer = jsonSerializer;
SourceCodeDownloadService = sourceCodeDownloadService;
AngularSourceCodeAdder = angularSourceCodeAdder;
RemoteServiceExceptionHandler = remoteServiceExceptionHandler;
CmdHelper = cmdHelper;
_cliHttpClientFactory = cliHttpClientFactory;
Logger = NullLogger<ProjectNpmPackageAdder>.Instance;
}
@ -202,4 +205,4 @@ namespace Volo.Abp.Cli.ProjectModification
}
}
}
}
}

5
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/ProjectNugetPackageAdder.cs

@ -25,6 +25,7 @@ namespace Volo.Abp.Cli.ProjectModification
public BundleCommand BundleCommand { get; }
public SourceCodeDownloadService SourceCodeDownloadService { get; }
public SolutionFileModifier SolutionFileModifier { get; }
public ICmdHelper CmdHelper { get; }
protected IJsonSerializer JsonSerializer { get; }
protected ProjectNpmPackageAdder NpmPackageAdder { get; }
@ -43,7 +44,8 @@ namespace Volo.Abp.Cli.ProjectModification
BundleCommand bundleCommand,
CliHttpClientFactory cliHttpClientFactory,
SourceCodeDownloadService sourceCodeDownloadService,
SolutionFileModifier solutionFileModifier)
SolutionFileModifier solutionFileModifier,
ICmdHelper cmdHelper)
{
JsonSerializer = jsonSerializer;
NpmPackageAdder = npmPackageAdder;
@ -53,6 +55,7 @@ namespace Volo.Abp.Cli.ProjectModification
BundleCommand = bundleCommand;
SourceCodeDownloadService = sourceCodeDownloadService;
SolutionFileModifier = solutionFileModifier;
CmdHelper = cmdHelper;
_cliHttpClientFactory = cliHttpClientFactory;
Logger = NullLogger<ProjectNugetPackageAdder>.Instance;
}

7
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/SolutionModuleAdder.cs

@ -30,6 +30,7 @@ namespace Volo.Abp.Cli.ProjectModification
public AngularSourceCodeAdder AngularSourceCodeAdder { get; }
public NewCommand NewCommand { get; }
public BundleCommand BundleCommand { get; }
public ICmdHelper CmdHelper { get; }
protected IJsonSerializer JsonSerializer { get; }
protected ProjectNugetPackageAdder ProjectNugetPackageAdder { get; }
@ -58,7 +59,8 @@ namespace Volo.Abp.Cli.ProjectModification
AngularSourceCodeAdder angularSourceCodeAdder,
NewCommand newCommand,
BundleCommand bundleCommand,
CliHttpClientFactory cliHttpClientFactory)
CliHttpClientFactory cliHttpClientFactory,
ICmdHelper cmdHelper)
{
JsonSerializer = jsonSerializer;
ProjectNugetPackageAdder = projectNugetPackageAdder;
@ -74,6 +76,7 @@ namespace Volo.Abp.Cli.ProjectModification
AngularSourceCodeAdder = angularSourceCodeAdder;
NewCommand = newCommand;
BundleCommand = bundleCommand;
CmdHelper = cmdHelper;
_cliHttpClientFactory = cliHttpClientFactory;
Logger = NullLogger<SolutionModuleAdder>.Instance;
}
@ -620,7 +623,7 @@ namespace Volo.Abp.Cli.ProjectModification
if (!string.IsNullOrEmpty(dbMigratorProject))
{
CmdHelper.RunCmd("cd \"" + Path.GetDirectoryName(dbMigratorProject) + "\" && dotnet run");
CmdHelper.RunCmd("cd \"" + Path.GetDirectoryName(dbMigratorProject) + "\" && dotnet run", out int exitCode);
}
}

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

@ -1,14 +1,15 @@
using System.Diagnostics;
using System.IO;
using System.Runtime.InteropServices;
using Volo.Abp.DependencyInjection;
namespace Volo.Abp.Cli.Utils
{
public static class CmdHelper
public class CmdHelper : ICmdHelper, ITransientDependency
{
public static int SuccessfulExitCode = 0;
private const int SuccessfulExitCode = 0;
public static void OpenWebPage(string url)
public void OpenWebPage(string url)
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
@ -25,45 +26,57 @@ namespace Volo.Abp.Cli.Utils
}
}
public static void Run(string file, string arguments)
public void Run(string file, string arguments)
{
var procStartInfo = new ProcessStartInfo(file, arguments);
Process.Start(procStartInfo)?.WaitForExit();
}
public static int RunCmd(string command)
public void RunCmd(string command, string workingDirectory = null)
{
RunCmd(command, out _, workingDirectory);
}
public void RunCmd(string command, out int exitCode, string workingDirectory = null)
{
var procStartInfo = new ProcessStartInfo(
GetFileName(),
GetArguments(command)
);
if (!string.IsNullOrEmpty(workingDirectory))
{
procStartInfo.WorkingDirectory = workingDirectory;
}
using (var process = Process.Start(procStartInfo))
{
process?.WaitForExit();
return process?.ExitCode ?? 0;
exitCode = process.ExitCode;
}
}
public static string RunCmdAndGetOutput(string command)
public string RunCmdAndGetOutput(string command, string workingDirectory = null)
{
return RunCmdAndGetOutput(command, out int _);
return RunCmdAndGetOutput(command, out int _, workingDirectory);
}
public static string RunCmdAndGetOutput(string command, out bool isExitCodeSuccessful)
public string RunCmdAndGetOutput(string command, out bool isExitCodeSuccessful, string workingDirectory = null)
{
var output = RunCmdAndGetOutput(command, out int exitCode);
var output = RunCmdAndGetOutput(command, out int exitCode, workingDirectory);
isExitCodeSuccessful = exitCode == SuccessfulExitCode;
return output;
}
public static string RunCmdAndGetOutput(string command, out int exitCode)
public string RunCmdAndGetOutput(string command, out int exitCode, string workingDirectory = null)
{
string output;
using (var process = new Process())
{
process.StartInfo = new ProcessStartInfo(CmdHelper.GetFileName())
process.StartInfo = new ProcessStartInfo(GetFileName())
{
Arguments = GetArguments(command),
UseShellExecute = false,
@ -72,6 +85,11 @@ namespace Volo.Abp.Cli.Utils
RedirectStandardError = true
};
if (!string.IsNullOrEmpty(workingDirectory))
{
process.StartInfo.WorkingDirectory = workingDirectory;
}
process.Start();
using (var standardOutput = process.StandardOutput)
@ -91,7 +109,7 @@ namespace Volo.Abp.Cli.Utils
return output.Trim();
}
public static string GetArguments(string command)
public string GetArguments(string command)
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX) || RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
@ -102,7 +120,7 @@ namespace Volo.Abp.Cli.Utils
return "/C \"" + command + "\"";
}
public static string GetFileName()
public string GetFileName()
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{

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

@ -0,0 +1,24 @@
namespace Volo.Abp.Cli.Utils
{
public interface ICmdHelper
{
void OpenWebPage(string url);
void Run(string file, string arguments);
string GetArguments(string command);
string GetFileName();
void RunCmd(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);
}
}

103
studio/src/Volo.Abp.Studio.Domain.CommonServices/Volo/Abp/Studio/Helpers/CmdHelper.cs

@ -1,103 +0,0 @@
using System.Diagnostics;
using System.IO;
using System.Runtime.InteropServices;
using Volo.Abp.DependencyInjection;
namespace Volo.Abp.Studio.Helpers
{
//todo: move this to volo.abp.cli.core!
public class CmdHelper : ICmdHelper, ITransientDependency
{
public void RunCmd(string command, string workingDirectory = null)
{
var procStartInfo = new ProcessStartInfo(
GetFileName(),
GetArguments(command)
);
if (!string.IsNullOrEmpty(workingDirectory))
{
procStartInfo.WorkingDirectory = workingDirectory;
}
using (var process = Process.Start(procStartInfo))
{
process?.WaitForExit();
}
}
public string RunCmdAndGetOutput(string command, string workingDirectory = null)
{
string output;
using (var process = new Process())
{
process.StartInfo = new ProcessStartInfo(GetFileName())
{
Arguments = GetArguments(command),
UseShellExecute = false,
CreateNoWindow = true,
RedirectStandardOutput = true,
RedirectStandardError = true
};
if (!string.IsNullOrEmpty(workingDirectory))
{
process.StartInfo.WorkingDirectory = workingDirectory;
}
process.Start();
using (var standardOutput = process.StandardOutput)
{
using (var standardError = process.StandardError)
{
output = standardOutput.ReadToEnd();
output += standardError.ReadToEnd();
}
}
process.WaitForExit();
}
return output.Trim();
}
private string GetArguments(string command)
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX) || RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
return "-c \"" + command + "\"";
}
//Windows default.
return "/C \"" + command + "\"";
}
private string GetFileName()
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
//Windows
return "cmd.exe";
}
//Linux or OSX
if (File.Exists("/bin/bash"))
{
return "/bin/bash";
}
if (File.Exists("/bin/sh"))
{
return "/bin/sh"; //some Linux distributions like Alpine doesn't have bash
}
throw new AbpException($"Cannot determine shell command for this OS! " +
$"Running on OS: {System.Runtime.InteropServices.RuntimeInformation.OSDescription} | " +
$"OS Architecture: {System.Runtime.InteropServices.RuntimeInformation.OSArchitecture} | " +
$"Framework: {System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription} | " +
$"Process Architecture{System.Runtime.InteropServices.RuntimeInformation.ProcessArchitecture}");
}
}
}

9
studio/src/Volo.Abp.Studio.Domain.CommonServices/Volo/Abp/Studio/Helpers/ICmdHelper.cs

@ -1,9 +0,0 @@
namespace Volo.Abp.Studio.Helpers
{
public interface ICmdHelper
{
void RunCmd(string command, string workingDirectory = null);
string RunCmdAndGetOutput(string command, string workingDirectory = null);
}
}

1
studio/src/Volo.Abp.Studio.Domain.CommonServices/Volo/Abp/Studio/Nuget/NugetPackageCacheManager.cs

@ -1,6 +1,7 @@
using System;
using System.IO;
using System.Threading.Tasks;
using Volo.Abp.Cli.Utils;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Studio.Helpers;

1
studio/src/Volo.Abp.Studio.Domain.CommonServices/Volo/Abp/Studio/Nuget/NugetSourceCodeStore.cs

@ -4,6 +4,7 @@ using System.Linq;
using System.Threading.Tasks;
using Volo.Abp.Cli.NuGet;
using Volo.Abp.Cli.ProjectBuilding;
using Volo.Abp.Cli.Utils;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Studio.Helpers;

Loading…
Cancel
Save