Replaced ANTLR parser with custom class
This commit is contained in:
@@ -47,14 +47,14 @@ public partial class MycroForge
|
||||
|
||||
if (name.FullyQualifiedName() is { Length: 2 } fullName)
|
||||
{
|
||||
folderPath = Path.Join(folderPath, fullName[0]);
|
||||
folderPath = Path.Combine(folderPath, fullName[0]);
|
||||
name = fullName[1];
|
||||
}
|
||||
|
||||
var moduleImportPath = folderPath.Replace('\\', '.').Replace('/', '.');
|
||||
var moduleName = name.Underscore().ToLower();
|
||||
var fileName = $"{moduleName}.py";
|
||||
var filePath = Path.Join(folderPath, fileName);
|
||||
var filePath = Path.Combine(folderPath, fileName);
|
||||
|
||||
await _context.CreateFile(filePath, Template);
|
||||
|
||||
|
||||
@@ -9,12 +9,12 @@ public partial class MycroForge
|
||||
{
|
||||
public partial class Generate : Command, ISubCommandOf<Api>
|
||||
{
|
||||
public Generate(IEnumerable<ISubCommandOf<Generate>> subCommands) :
|
||||
public Generate(IEnumerable<ISubCommandOf<Generate>> commands) :
|
||||
base("generate", "Generate an API item")
|
||||
{
|
||||
AddAlias("g");
|
||||
foreach (var subCommandOf in subCommands.Cast<Command>())
|
||||
AddCommand(subCommandOf);
|
||||
foreach (var command in commands.Cast<Command>())
|
||||
AddCommand(command);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,7 +74,7 @@ public partial class MycroForge
|
||||
|
||||
if (name.FullyQualifiedName() is { Length: 2 } fullName)
|
||||
{
|
||||
folderPath = Path.Join(folderPath, fullName[0]);
|
||||
folderPath = Path.Combine(folderPath, fullName[0]);
|
||||
name = fullName[1];
|
||||
}
|
||||
|
||||
@@ -89,9 +89,8 @@ public partial class MycroForge
|
||||
code = code.Replace("%table_name%", name.Underscore().ToLower().Pluralize());
|
||||
code = code.Replace("%column_definitions%", columnDefinitions);
|
||||
|
||||
// var folderPath = Path.Join(, path);
|
||||
var fileName = $"{name.Underscore().ToLower()}.py";
|
||||
var filePath = Path.Join(folderPath, fileName);
|
||||
var filePath = Path.Combine(folderPath, fileName);
|
||||
await _context.CreateFile(filePath, code);
|
||||
|
||||
var importPathParts = new[] { folderPath, fileName.Replace(".py", "") }
|
||||
@@ -106,6 +105,10 @@ public partial class MycroForge
|
||||
var env = await _context.ReadFile($"{Features.Db.FeatureName}/env.py");
|
||||
env = new DbEnvModifier(env, importPath, className).Rewrite();
|
||||
await _context.WriteFile($"{Features.Db.FeatureName}/env.py", env);
|
||||
|
||||
var main = await _context.ReadFile("main.py");
|
||||
main = new MainModifier(main).Initialize().Import(importPath, className).Rewrite();
|
||||
await _context.WriteFile("main.py", main);
|
||||
}
|
||||
|
||||
private List<ColumnDefinition> GetColumnDefinitions(string[] fields)
|
||||
|
||||
@@ -60,11 +60,11 @@ public partial class MycroForge
|
||||
|
||||
if (name.FullyQualifiedName() is { Length: 2} fullName)
|
||||
{
|
||||
folderPath = Path.Join(folderPath, fullName[0]);
|
||||
folderPath = Path.Combine(folderPath, fullName[0]);
|
||||
name = fullName[1];
|
||||
}
|
||||
|
||||
var filePath = Path.Join(folderPath, $"{name.Underscore().ToLower()}.py");
|
||||
var filePath = Path.Combine(folderPath, $"{name.Underscore().ToLower()}.py");
|
||||
var className = Path.GetFileName(name).Pascalize();
|
||||
var code = string.Join('\n', withSession ? WithSessionTemplate : DefaultTemplate)
|
||||
.Replace("%class_name%", className);
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
using System.CommandLine;
|
||||
using System.Diagnostics;
|
||||
using Microsoft.Scripting.Utils;
|
||||
using MycroForge.CLI.Commands.Interfaces;
|
||||
|
||||
namespace MycroForge.CLI.Commands;
|
||||
@@ -28,13 +27,13 @@ public partial class MycroForge
|
||||
|
||||
private static async Task<string> CreateFile(string? name = null, string fileExtension = "py")
|
||||
{
|
||||
var folder = Path.Join(
|
||||
var folder = Path.Combine(
|
||||
Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".m4g"
|
||||
);
|
||||
|
||||
Directory.CreateDirectory(folder);
|
||||
|
||||
var filePath = Path.Join(folder, $"{name}.{fileExtension}");
|
||||
var filePath = Path.Combine(folder, $"{name}.{fileExtension}");
|
||||
|
||||
if (File.Exists(filePath))
|
||||
throw new Exception($"File {filePath} already exists.");
|
||||
|
||||
@@ -26,11 +26,11 @@ public partial class MycroForge
|
||||
|
||||
private static async Task EditFile(string name)
|
||||
{
|
||||
var folder = Path.Join(
|
||||
var folder = Path.Combine(
|
||||
Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".m4g"
|
||||
);
|
||||
|
||||
var file = Path.Join(folder, $"{name}.py");
|
||||
var file = Path.Combine(folder, $"{name}.py");
|
||||
|
||||
if (!File.Exists(file))
|
||||
throw new Exception($"File {file} does not exists.");
|
||||
|
||||
@@ -16,7 +16,7 @@ public partial class MycroForge
|
||||
|
||||
private void Execute()
|
||||
{
|
||||
var folder = Path.Join(
|
||||
var folder = Path.Combine(
|
||||
Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".m4g"
|
||||
);
|
||||
|
||||
|
||||
@@ -7,9 +7,10 @@ public partial class MycroForge : RootCommand
|
||||
{
|
||||
public override string Name => "m4g";
|
||||
|
||||
public MycroForge(IEnumerable<ISubCommandOf<MycroForge>> commands) : base("The MycroForge CLI tool.")
|
||||
public MycroForge(IEnumerable<ISubCommandOf<MycroForge>> commands) :
|
||||
base("The MycroForge CLI tool.")
|
||||
{
|
||||
foreach (var subCommandOf in commands.Cast<Command>())
|
||||
AddCommand(subCommandOf);
|
||||
foreach (var command in commands.Cast<Command>())
|
||||
AddCommand(command);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user