39 lines
1.4 KiB
C#
39 lines
1.4 KiB
C#
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<Add>
|
|
{
|
|
private static readonly Option<int> ApiPortOption = new(name: "--api-port", description: "The API port");
|
|
|
|
private readonly ProjectContext _context;
|
|
private readonly OptionsContainer _optionsContainer;
|
|
private readonly List<IFeature> _features;
|
|
|
|
public Api(ProjectContext context, OptionsContainer optionsContainer, IEnumerable<IFeature> 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);
|
|
}
|
|
}
|
|
}
|
|
} |