mycroforge/MycroForge.CLI/Commands/MycroForge.Plugin.Init.cs
mdnapo 457429f7ec
All checks were successful
Build and publish MycroForge.CLI / test (push) Has been skipped
Test MycroForge.CLI / test (push) Successful in 5m39s
Improved plugin feature
2024-10-13 13:39:56 +02:00

39 lines
1.5 KiB
C#

using System.CommandLine;
using MycroForge.Core;
using MycroForge.Core.Contract;
namespace MycroForge.CLI.Commands;
public partial class MycroForge
{
public partial class Plugin
{
public class Init : Command, ISubCommandOf<Plugin>
{
private static readonly Argument<string> NamespaceArgument =
new(name: "namespace", description: "The namespace of your project");
private static readonly Argument<string> ClassArgument =
new(name: "class", description: "The class name of the generated command");
private static readonly Argument<string> CommandArgument =
new(name: "command", description: "The command name that will be added to 'm4g'");
private readonly ProjectContext _context;
public Init(ProjectContext context) : base("init", "Initialize a basic plugin project")
{
_context = context;
AddArgument(NamespaceArgument);
AddArgument(ClassArgument);
AddArgument(CommandArgument);
this.SetHandler(ExecuteAsync, NamespaceArgument, ClassArgument, CommandArgument);
}
private async Task ExecuteAsync(string @namespace, string @class, string command)
{
await _context.Bash($"dotnet new m4gp -n {@namespace} --class {@class} --command {command}");
}
}
}
}