Files
Yi.Admin/Yi.Abp.Net8/tool/Yi.Abp.Tool/CommandInvoker.cs

47 lines
1.5 KiB
C#
Raw Normal View History

2024-11-05 18:50:15 +08:00
using System;
using System.Collections.Generic;
using System.Linq;
2024-11-06 00:05:29 +08:00
using System.Reflection;
2024-11-05 18:50:15 +08:00
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()
{
2024-11-05 22:12:30 +08:00
Application.HelpOption("-h|--help");
2024-11-06 00:05:29 +08:00
Application.VersionOption("-v|--versions", Assembly.GetExecutingAssembly().GetName().Version.ToString());
2024-11-05 18:50:15 +08:00
foreach (var command in _commands)
{
2024-11-05 22:12:30 +08:00
CommandLineApplication childrenCommandLineApplication = new CommandLineApplication(true)
{
Name = command.Command,
Parent = Application,
Description =command.Description
};
Application.Commands.Add(childrenCommandLineApplication);
command.CommandLineApplication(childrenCommandLineApplication);
2024-11-05 18:50:15 +08:00
}
}
public async Task InvokerAsync(string[] args)
{
Application.Execute(args);
}
}
}