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 { private static readonly Argument 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); await new RequestClassGenerator(_context).Generate(fqn, RequestClassGenerator.Type.Create); await new RequestClassGenerator(_context).Generate(fqn, RequestClassGenerator.Type.Update); await new CrudRouterGenerator(_context).Generate(fqn); } } } } }