mycroforge/MycroForge.CLI/Commands/MycroForge.Api.Generate.Crud.cs

41 lines
1.6 KiB
C#

using System.CommandLine;
using MycroForge.CLI.CodeGen;
using MycroForge.Core;
using MycroForge.Core.Contract;
namespace MycroForge.CLI.Commands;
public partial class MycroForge
{
public partial class Api
{
public partial class Generate
{
public class Crud : Command, ISubCommandOf<Generate>
{
private static readonly Argument<string> EntityArgument =
new(name: "entity", description: "The entity to target");
private readonly ProjectContext _context;
public Crud(ProjectContext context)
: base("crud", "Generated CRUD functionality for an entity")
{
_context = context;
AddArgument(EntityArgument);
this.SetHandler(ExecuteAsync, EntityArgument);
}
private async Task ExecuteAsync(string entity)
{
var fqn = new FullyQualifiedName(entity);
await new CrudServiceGenerator(_context).Generate(fqn.Path, fqn.PascalizedName);
await new RequestClassGenerator(_context).Generate(fqn.Path, fqn.PascalizedName, RequestClassGenerator.Type.Create);
await new RequestClassGenerator(_context).Generate(fqn.Path, fqn.PascalizedName, RequestClassGenerator.Type.Update);
await new CrudRouterGenerator(_context).Generate(fqn.Path, fqn.PascalizedName);
}
}
}
}
}