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 Api : Command, ISubCommandOf { private static readonly Option ApiPortOption = new(name: "--api-port", description: "The API port"); private readonly ProjectContext _context; private readonly OptionsContainer _optionsContainer; private readonly List _features; public Api(ProjectContext context, OptionsContainer optionsContainer, IEnumerable features) : base(Features.Api.FeatureName, "Add FastAPI to the project") { _context = context; _optionsContainer = optionsContainer; _features = features.ToList(); AddOption(ApiPortOption); this.SetHandler(ExecuteAsync, ApiPortOption); } private async Task ExecuteAsync(int apiPort) { _optionsContainer.Set(new Features.Api.Options { ApiPort = apiPort }); var feature = _features.First(f => f.Name == Features.Api.FeatureName); await feature.ExecuteAsync(_context); } } } }