using System.CommandLine; using MycroForge.CLI.Features; using MycroForge.Core; using MycroForge.Core.Contract; namespace MycroForge.CLI.Commands; public partial class MycroForge { public partial class Add { public class Db : Command, ISubCommandOf { private static readonly Option DbhPortOption = new( aliases: ["--database-host-port", "--dbh-port"], description: "The database host port" ); private static readonly Option DbuPortOption = new( aliases: ["--database-ui-port", "--dbu-port"], description: "The database UI port" ); private static readonly Option DbuPlatformOption = new( aliases: ["--database-ui-platform", "--dbu-platform"], description: "The docker platform for the PhpMyAdmin image" ); private readonly ProjectContext _context; private readonly OptionsContainer _optionsContainer; private readonly List _features; public Db(ProjectContext context, OptionsContainer optionsContainer, IEnumerable features) : base(Features.Db.FeatureName, "Add SQLAlchemy & Alembic to the project") { _context = context; _optionsContainer = optionsContainer; _features = features.ToList(); AddOption(DbhPortOption); AddOption(DbuPortOption); AddOption(DbuPlatformOption); this.SetHandler(ExecuteAsync, DbhPortOption, DbuPortOption, DbuPlatformOption); } private async Task ExecuteAsync( int dbhPort, int dbuPort, ProjectConfig.DbConfig.DbuPlatformOptions dbuPlatform ) { _optionsContainer.Set(new Features.Db.Options { DbhPort = dbhPort, DbuPort = dbuPort, DbuPlatform = dbuPlatform }); var feature = _features.First(f => f.Name == Features.Db.FeatureName); await feature.ExecuteAsync(_context); } } } }