Files
Yi.Framework/Yi.Abp.Net8/tool/Yi.Abp.Tool/CommandInvoker.cs
2024-11-05 18:50:15 +08:00

45 lines
1.3 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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);
}
}
}