feat: 完成add-module功能

This commit is contained in:
橙子
2024-06-08 21:51:45 +08:00
parent b69267d94f
commit c23ff654ed
11 changed files with 101 additions and 53 deletions

View File

@@ -13,7 +13,7 @@ namespace Yi.Abp.Tool.Commands
public async Task InvokerAsync(Dictionary<string, string> options, string[] args)
{
//只有一个add
//只有一个add-module
if (args.Length <= 1)
{
throw new UserFriendlyException("命令错误add-module命令后必须添加 模块名");
@@ -23,18 +23,21 @@ namespace Yi.Abp.Tool.Commands
var moduleName = args[1];
options.TryGetValue("modulePath", out var modulePath);
//模块路径默认按小写规则,当前路径
if (string.IsNullOrEmpty(modulePath))
{
throw new UserFriendlyException("命令错误,添加模块,必须指定模块路径");
modulePath = moduleName.ToLower().Replace(".", "-");
}
//解决方案默认在模块文件夹上一级也可以通过s进行指定
var slnPath = string.Empty;
options.TryGetValue("s", out var slnPath1);
options.TryGetValue("solution", out var slnPath2);
slnPath = string.IsNullOrEmpty(slnPath1) ? slnPath2 : slnPath1;
if (string.IsNullOrEmpty(slnPath))
{
slnPath = "./";
slnPath = "../";
}
CheckFirstSlnPath(slnPath);

View File

@@ -0,0 +1,50 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Yi.Abp.Tool.Commands
{
public class CloneCommand : ICommand
{
public List<string> CommandStrs => new List<string> { "clone"};
private const string cloneAddress= "https://gitee.com/ccnetcore/Yi";
public Task InvokerAsync(Dictionary<string, string> options, string[] args)
{
StartCmd($"git clone {cloneAddress}");
return Task.CompletedTask;
}
/// <summary>
/// 执行cmd命令
/// </summary>
/// <param name="cmdCommands"></param>
private void StartCmd(params string[] cmdCommands)
{
ProcessStartInfo psi = new ProcessStartInfo
{
FileName = "cmd.exe",
Arguments = $"/c chcp 65001&{string.Join("&", cmdCommands)}",
RedirectStandardInput = true,
RedirectStandardOutput = true,
RedirectStandardError = true,
CreateNoWindow = true,
UseShellExecute = false
};
Process proc = new Process
{
StartInfo = psi
};
proc.Start();
string output = proc.StandardOutput.ReadToEnd();
Console.WriteLine(output);
proc.WaitForExit();
}
}
}

View File

@@ -30,8 +30,7 @@ namespace Yi.Abp.Tool.Commands
> help: 查看帮助列表,写下命令` yi-abp help <command> `
> new: 创建模块模板` yi-abp new <name> -t module -csf `
> new: 创建项目模板` yi-abp new <name> -csf `
> add-module: 将内容添加到当前解决方案` yi-abp add-module <moduleName> -modulePath <path> [-s <slnPath>] `
- add例子yi-abp add-module Acme.Demo -s "D:\code\csharp\source\Yi\Yi.Abp.Net8" -modulePath "D:\\code\\csharp\\source\\Yi\\Yi.Abp.Net8\\module\\acme-demo"
> add-module: 将内容添加到当前解决方案` yi-abp add-module <moduleName> [-modulePath <path>] [-s <slnPath>] `
""");
return Task.CompletedTask;