Ading comments and cleaning up
This commit is contained in:
@@ -1,28 +1,48 @@
|
||||
using Humanizer;
|
||||
using MycroForge.CLI.Extensions;
|
||||
|
||||
namespace MycroForge.CLI.Commands;
|
||||
|
||||
public class FullyQualifiedName
|
||||
{
|
||||
public string Path { get; }
|
||||
public string FolderPath { get; }
|
||||
public string PascalizedName { get; }
|
||||
public string SnakeCasedName { get; }
|
||||
|
||||
public bool HasPath => Path.Length > 0;
|
||||
public string FilePath =>
|
||||
string.IsNullOrEmpty(FolderPath.Trim())
|
||||
? SnakeCasedName
|
||||
: Path.Join(FolderPath, SnakeCasedName);
|
||||
|
||||
public bool HasPath => FolderPath.Length > 0;
|
||||
|
||||
|
||||
|
||||
public FullyQualifiedName(string name)
|
||||
{
|
||||
var path = string.Empty;
|
||||
|
||||
|
||||
if (name.Split(':').Select(s => s.Trim()).ToArray() is { Length: 2 } fullName)
|
||||
{
|
||||
path = fullName[0];
|
||||
name = fullName[1];
|
||||
}
|
||||
|
||||
Path = path;
|
||||
|
||||
FolderPath = path;
|
||||
PascalizedName = name.Pascalize();
|
||||
SnakeCasedName = name.Underscore().ToLower();
|
||||
SnakeCasedName = SnakeCase(name);
|
||||
}
|
||||
}
|
||||
|
||||
public string GetImportPath(params string[] root)
|
||||
{
|
||||
if (root.Length == 0)
|
||||
return string.Join('.', FilePath).SlashesToDots();
|
||||
|
||||
var importRoot = string.Join('.', root);
|
||||
|
||||
return string.Join('.', SnakeCase(importRoot), FilePath).SlashesToDots();
|
||||
}
|
||||
|
||||
private static string SnakeCase(string value) => value.Underscore().ToLower();
|
||||
|
||||
// private static string SlashesToDots(string value) => value.Replace('\\', '.').Replace('/', '.');
|
||||
}
|
||||
@@ -21,6 +21,11 @@ public partial class MycroForge
|
||||
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;
|
||||
@@ -34,12 +39,22 @@ public partial class MycroForge
|
||||
|
||||
AddOption(DbhPortOption);
|
||||
AddOption(DbuPortOption);
|
||||
this.SetHandler(ExecuteAsync, DbhPortOption, DbuPortOption);
|
||||
AddOption(DbuPlatformOption);
|
||||
this.SetHandler(ExecuteAsync, DbhPortOption, DbuPortOption, DbuPlatformOption);
|
||||
}
|
||||
|
||||
private async Task ExecuteAsync(int dbhPort, int dbuPort)
|
||||
private async Task ExecuteAsync(
|
||||
int dbhPort,
|
||||
int dbuPort,
|
||||
ProjectConfig.DbConfig.DbuPlatformOptions dbuPlatform
|
||||
)
|
||||
{
|
||||
_optionsContainer.Set(new Features.Db.Options { DbhPort = dbhPort, DbuPort = dbuPort });
|
||||
_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);
|
||||
}
|
||||
|
||||
@@ -29,11 +29,10 @@ public partial class MycroForge
|
||||
private async Task ExecuteAsync(string entity)
|
||||
{
|
||||
var fqn = new FullyQualifiedName(entity);
|
||||
|
||||
await new CrudServiceGenerator(_context).Generate(fqn.Path, fqn.PascalizedName);
|
||||
await new RequestClassGenerator(_context).Generate(fqn.Path, fqn.PascalizedName, RequestClassGenerator.Type.Create);
|
||||
await new RequestClassGenerator(_context).Generate(fqn.Path, fqn.PascalizedName, RequestClassGenerator.Type.Update);
|
||||
await new CrudRouterGenerator(_context).Generate(fqn.Path, fqn.PascalizedName);
|
||||
await new CrudServiceGenerator(_context).Generate(fqn);
|
||||
await new RequestClassGenerator(_context).Generate(fqn, RequestClassGenerator.Type.Create);
|
||||
await new RequestClassGenerator(_context).Generate(fqn, RequestClassGenerator.Type.Update);
|
||||
await new CrudRouterGenerator(_context).Generate(fqn);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ public partial class MycroForge
|
||||
_context.AssertDirectoryExists(folderPath);
|
||||
|
||||
if (fqn.HasPath)
|
||||
folderPath = Path.Combine(folderPath, fqn.Path);
|
||||
folderPath = Path.Combine(folderPath, fqn.FolderPath);
|
||||
|
||||
var fileName = $"{fqn.SnakeCasedName}.py";
|
||||
var filePath = Path.Combine(folderPath, fileName);
|
||||
|
||||
@@ -75,7 +75,7 @@ public partial class MycroForge
|
||||
_context.AssertDirectoryExists(Features.Db.FeatureName);
|
||||
|
||||
if (fqn.HasPath)
|
||||
folderPath = Path.Combine(folderPath, fqn.Path);
|
||||
folderPath = Path.Combine(folderPath, fqn.FolderPath);
|
||||
|
||||
var _columns = GetColumnDefinitions(columns.ToArray());
|
||||
var typeImports = string.Join(", ", _columns.Select(c => c.OrmType.Split('(').First()).Distinct());
|
||||
|
||||
@@ -23,7 +23,8 @@ public partial class MycroForge
|
||||
{
|
||||
var config = await _context.LoadConfig();
|
||||
var env = $"DBH_PORT={config.Db.DbhPort} DBU_PORT={config.Db.DbuPort}";
|
||||
await _context.Bash($"{env} docker compose -f {Features.Db.FeatureName}.docker-compose.yml up -d");
|
||||
var command = $"{env} docker compose -f {Features.Db.FeatureName}.docker-compose.yml up -d";
|
||||
await _context.Bash(command);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ public partial class MycroForge
|
||||
private async Task ExecuteAsync()
|
||||
{
|
||||
await _context.Bash(
|
||||
// Set the log level to ERROR to prevent warnings concerning environment variables not being set.
|
||||
$"docker --log-level ERROR compose -f {Features.Db.FeatureName}.docker-compose.yml down"
|
||||
);
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ public partial class MycroForge
|
||||
var folderPath = string.Empty;
|
||||
|
||||
if (fqn.HasPath)
|
||||
folderPath = Path.Combine(folderPath, fqn.Path);
|
||||
folderPath = Path.Combine(folderPath, fqn.FolderPath);
|
||||
|
||||
var filePath = Path.Combine(folderPath, $"{fqn.SnakeCasedName}.py");
|
||||
var template = withSession ? WithSessionTemplate : DefaultTemplate;
|
||||
|
||||
@@ -15,6 +15,7 @@ public partial class MycroForge
|
||||
ApiPort = ctx.ParseResult.GetValueForOption(ApiPortOption),
|
||||
DbhPort = ctx.ParseResult.GetValueForOption(DbhPortOption),
|
||||
DbuPort = ctx.ParseResult.GetValueForOption(DbuPortOption),
|
||||
DbuPlatform = ctx.ParseResult.GetValueForOption(DbuPlatformOption),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
namespace MycroForge.CLI.Commands;
|
||||
using MycroForge.Core;
|
||||
|
||||
namespace MycroForge.CLI.Commands;
|
||||
|
||||
public partial class MycroForge
|
||||
{
|
||||
@@ -11,6 +13,7 @@ public partial class MycroForge
|
||||
public int? ApiPort { get; set; }
|
||||
public int? DbhPort { get; set; }
|
||||
public int? DbuPort { get; set; }
|
||||
public ProjectConfig.DbConfig.DbuPlatformOptions DbuPlatform { get; set; }
|
||||
|
||||
public Features.Api.Options ApiOptions => new()
|
||||
{
|
||||
@@ -20,7 +23,8 @@ public partial class MycroForge
|
||||
public Features.Db.Options DbOptions => new()
|
||||
{
|
||||
DbhPort = DbhPort <= 0 ? 5050 : DbhPort,
|
||||
DbuPort = DbuPort <= 0 ? 5051 : DbhPort
|
||||
DbuPort = DbuPort <= 0 ? 5051 : DbhPort,
|
||||
DbuPlatform = DbuPlatform
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,6 +39,11 @@ public partial class MycroForge
|
||||
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 List<IFeature> _features;
|
||||
private readonly OptionsContainer _optionsContainer;
|
||||
@@ -55,6 +60,7 @@ public partial class MycroForge
|
||||
AddOption(ApiPortOption);
|
||||
AddOption(DbhPortOption);
|
||||
AddOption(DbuPortOption);
|
||||
AddOption(DbuPlatformOption);
|
||||
|
||||
this.SetHandler(ExecuteAsync, new Binder());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user