feat: 搭建tool
This commit is contained in:
45
Yi.Abp.Net8/tool/Yi.Abp.Tool/CommandInvoker.cs
Normal file
45
Yi.Abp.Net8/tool/Yi.Abp.Tool/CommandInvoker.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.CommandLineUtils;
|
||||
using Volo.Abp.DependencyInjection;
|
||||
using static System.Runtime.InteropServices.JavaScript.JSType;
|
||||
|
||||
namespace Yi.Abp.Tool
|
||||
{
|
||||
public class CommandInvoker : ISingletonDependency
|
||||
{
|
||||
private readonly IEnumerable<ICommand> _commands;
|
||||
private CommandLineApplication Application { get; }
|
||||
|
||||
public CommandInvoker(IEnumerable<ICommand> commands)
|
||||
{
|
||||
_commands = commands;
|
||||
Application = new CommandLineApplication();
|
||||
InitCommand();
|
||||
}
|
||||
|
||||
private void InitCommand()
|
||||
{
|
||||
Application.HelpOption("-h");
|
||||
|
||||
foreach (var command in _commands)
|
||||
{
|
||||
Application.Command(command.Command, con => command.CommandLineApplicationAsync(con).Wait());
|
||||
}
|
||||
}
|
||||
|
||||
public async Task InvokerAsync(string[] args)
|
||||
{
|
||||
//使用哪个命令,根据第一参数来判断,如果都不是,打印help
|
||||
// foreach (var commandLineApplication in Application.Commands)
|
||||
// {
|
||||
// commandLineApplication.Execute(args);
|
||||
// }
|
||||
|
||||
Application.Execute(args);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user