Files
Yi.Framework/Yi.Abp.Net8/tool/Yi.Abp.Tool/CommandInvoker.cs
2024-11-05 22:12:30 +08:00

46 lines
1.4 KiB
C#

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|--help");
Application.VersionOption("-v|--versions","1.0.0");
foreach (var command in _commands)
{
CommandLineApplication childrenCommandLineApplication = new CommandLineApplication(true)
{
Name = command.Command,
Parent = Application,
Description =command.Description
};
Application.Commands.Add(childrenCommandLineApplication);
command.CommandLineApplication(childrenCommandLineApplication);
}
}
public async Task InvokerAsync(string[] args)
{
Application.Execute(args);
}
}
}