2024-11-05 22:12:30 +08:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
|
using System.Linq;
|
2025-01-21 19:35:30 +08:00
|
|
|
|
using System.Runtime.InteropServices;
|
2024-11-05 22:12:30 +08:00
|
|
|
|
using System.Text;
|
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
using Microsoft.Extensions.CommandLineUtils;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Yi.Abp.Tool.Commands
|
|
|
|
|
|
{
|
|
|
|
|
|
public class CloneCommand : ICommand
|
|
|
|
|
|
{
|
2024-11-08 12:35:54 +08:00
|
|
|
|
private const string CloneAddress= "https://gitee.com/ccnetcore/Yi";
|
2024-11-05 22:12:30 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public string Command => "clone";
|
2024-11-08 12:35:54 +08:00
|
|
|
|
public string? Description => "克隆最新YiFramework源代码,需依赖git";
|
2024-11-05 22:12:30 +08:00
|
|
|
|
|
|
|
|
|
|
public void CommandLineApplication(CommandLineApplication application)
|
|
|
|
|
|
{
|
|
|
|
|
|
application.OnExecute(() =>
|
|
|
|
|
|
{
|
2024-11-29 15:25:16 +08:00
|
|
|
|
Console.WriteLine("正在克隆,请耐心等待");
|
2024-11-08 12:35:54 +08:00
|
|
|
|
StartCmd($"git clone {CloneAddress}");
|
2024-11-05 22:12:30 +08:00
|
|
|
|
return 0;
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 执行cmd命令
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="cmdCommands"></param>
|
|
|
|
|
|
private void StartCmd(params string[] cmdCommands)
|
|
|
|
|
|
{
|
|
|
|
|
|
ProcessStartInfo psi = new ProcessStartInfo
|
|
|
|
|
|
{
|
|
|
|
|
|
RedirectStandardInput = true,
|
|
|
|
|
|
RedirectStandardOutput = true,
|
|
|
|
|
|
RedirectStandardError = true,
|
|
|
|
|
|
CreateNoWindow = true,
|
|
|
|
|
|
UseShellExecute = false
|
|
|
|
|
|
};
|
2025-01-21 19:35:30 +08:00
|
|
|
|
// 判断操作系统
|
|
|
|
|
|
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
|
|
|
|
|
{
|
|
|
|
|
|
psi.FileName = "cmd.exe";
|
|
|
|
|
|
psi.Arguments = $"/c chcp 65001&{string.Join("&", cmdCommands)}";
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX) || RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
|
|
|
|
|
{
|
|
|
|
|
|
psi.FileName = "/bin/bash";
|
|
|
|
|
|
psi.Arguments = $"-c \"{string.Join("; ", cmdCommands)}\"";
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-11-05 22:12:30 +08:00
|
|
|
|
Process proc = new Process
|
|
|
|
|
|
{
|
|
|
|
|
|
StartInfo = psi
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
proc.Start();
|
|
|
|
|
|
string output = proc.StandardOutput.ReadToEnd();
|
|
|
|
|
|
Console.WriteLine(output);
|
|
|
|
|
|
|
|
|
|
|
|
proc.WaitForExit();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|