48 lines
1.8 KiB
C#
48 lines
1.8 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 Db : Command, ISubCommandOf<Add>
|
|
{
|
|
private static readonly Option<int> DbhPortOption = new(
|
|
aliases: ["--database-host-port", "--dbh-port"],
|
|
description: "The database host port"
|
|
);
|
|
|
|
private static readonly Option<int> DbuPortOption = new(
|
|
aliases: ["--database-ui-port", "--dbu-port"],
|
|
description: "The database UI port"
|
|
);
|
|
|
|
private readonly ProjectContext _context;
|
|
private readonly OptionsContainer _optionsContainer;
|
|
private readonly List<IFeature> _features;
|
|
|
|
public Db(ProjectContext context, OptionsContainer optionsContainer, IEnumerable<IFeature> features) :
|
|
base(Features.Db.FeatureName, "Add SQLAlchemy & Alembic to the project")
|
|
{
|
|
_context = context;
|
|
_optionsContainer = optionsContainer;
|
|
_features = features.ToList();
|
|
|
|
AddOption(DbhPortOption);
|
|
AddOption(DbuPortOption);
|
|
this.SetHandler(ExecuteAsync, DbhPortOption, DbuPortOption);
|
|
}
|
|
|
|
private async Task ExecuteAsync(int dbhPort, int dbuPort)
|
|
{
|
|
_optionsContainer.Set(new Features.Db.Options { DbhPort = dbhPort, DbuPort = dbuPort });
|
|
var feature = _features.First(f => f.Name == Features.Db.FeatureName);
|
|
await feature.ExecuteAsync(_context);
|
|
}
|
|
}
|
|
}
|
|
} |