[WIP] embed code generation
parent
67ff158741
commit
89b75036f9
@ -0,0 +1,73 @@
|
||||
using cli.Model;
|
||||
using Microsoft.Extensions.CommandLineUtils;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.AspNet.Hosting;
|
||||
using Microsoft.Extensions.OptionsModel;
|
||||
|
||||
using cli.Services;
|
||||
using cli.Settings;
|
||||
|
||||
namespace cli.Commands
|
||||
{
|
||||
public class GenerationCommander : ICommander
|
||||
{
|
||||
|
||||
public GenerationCommander()
|
||||
{
|
||||
}
|
||||
|
||||
public CommandLineApplication Integrate(CommandLineApplication rootApp)
|
||||
{
|
||||
CommandArgument nsarg=null;
|
||||
CommandArgument mdClass=null;
|
||||
CommandArgument ctrlName=null;
|
||||
CommandArgument rPath=null;
|
||||
CommandArgument dbCtx=null;
|
||||
|
||||
var cmd = rootApp.Command("mvc", config => {
|
||||
config.FullName = "mvc controller";
|
||||
config.Description = "generates an mvc controller";
|
||||
nsarg = config.Argument("ns","default name space");
|
||||
mdClass = config.Argument("mc","Model class name");
|
||||
ctrlName = config.Argument("cn", "Controller name");
|
||||
rPath = config.Argument("rp", "Relative path");
|
||||
config.HelpOption("-? | -h | --help");
|
||||
});
|
||||
cmd.OnExecute(() => {
|
||||
var host = new WebHostBuilder();
|
||||
var hostengnine = host.UseEnvironment("Development")
|
||||
.UseServer("cli")
|
||||
.UseStartup<Startup>()
|
||||
.Build();
|
||||
var app = hostengnine.Start();
|
||||
var mailer = app.Services.GetService<MvcGenerator>();
|
||||
var loggerFactory = app.Services.GetService<ILoggerFactory>();
|
||||
var logger = loggerFactory.CreateLogger<GenerationCommander>();
|
||||
var options = app.Services.GetService<IOptions<GenMvcSettings>>();
|
||||
|
||||
MvcGenerator generator = app.Services.GetService<MvcGenerator>();
|
||||
|
||||
var modelFullName = mdClass?.Value ?? options?.Value.ModelFullName;
|
||||
var nameSpace = nsarg?.Value?? options?.Value.NameSpace;
|
||||
var dbContext = dbCtx?.Value?? options?.Value.DbContextFullName;
|
||||
var controllerName = ctrlName?.Value?? options?.Value.ControllerName;
|
||||
var relativePath = rPath?.Value ?? options?.Value.RelativePath;
|
||||
|
||||
logger.LogInformation("Starting generation");
|
||||
logger.LogInformation($"Using parameters : modelFullName:{modelFullName} nameSpace:{nameSpace} dbContext:{dbContext} controllerName:{controllerName} relativePath:{relativePath}");
|
||||
|
||||
generator.Generate(modelFullName,
|
||||
nameSpace,
|
||||
dbContext,
|
||||
controllerName,
|
||||
relativePath);
|
||||
|
||||
logger.LogInformation("Finished generation");
|
||||
|
||||
return 0;
|
||||
});
|
||||
return cmd;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
using System;
|
||||
using Microsoft.Extensions.CodeGenerators.Mvc.Controller;
|
||||
|
||||
namespace cli.Services
|
||||
{
|
||||
|
||||
public class MvcGenerator : CommandLineGenerator
|
||||
{
|
||||
CommandLineGeneratorModel _model;
|
||||
public MvcGenerator (IServiceProvider services): base (services)
|
||||
{
|
||||
_model = new CommandLineGeneratorModel();
|
||||
}
|
||||
|
||||
public async void Generate(
|
||||
string modelClass,
|
||||
string ns,
|
||||
string dbContextFullName,
|
||||
string controllerName,
|
||||
string relativeFolderPath
|
||||
)
|
||||
{
|
||||
_model.ControllerName = controllerName;
|
||||
_model.ModelClass = modelClass;
|
||||
_model.DataContextClass = dbContextFullName;
|
||||
_model.RelativeFolderPath = relativeFolderPath;
|
||||
await GenerateCode(_model);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
namespace cli.Settings
|
||||
{
|
||||
public class GenMvcSettings
|
||||
{
|
||||
public string NameSpace { get; set; }
|
||||
public string ModelFullName { get; set; }
|
||||
public string ControllerName { get; set; }
|
||||
public string AppBase { get; set; }
|
||||
public string RelativePath { get; set; }
|
||||
public string DbContextFullName { get; set; }
|
||||
|
||||
// FIXME this appears to be dropped soon ... as all configuration should be concerned
|
||||
public string ConfigurationName { get; set; } = "Development";
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue