63 lines
2.3 KiB
C#
63 lines
2.3 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 static readonly Option<ProjectConfig.DbConfig.DbuPlatformOptions> 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<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);
|
|
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);
|
|
}
|
|
}
|
|
}
|
|
} |