Adding entity linking
This commit is contained in:
@@ -14,20 +14,4 @@ public partial class MycroForge
|
||||
AddCommand((subCommandOf as Command)!);
|
||||
}
|
||||
}
|
||||
|
||||
public class Run : Command, ISubCommandOf<MycroForge>
|
||||
{
|
||||
public Run() : base("run", "Run your app")
|
||||
{
|
||||
this.SetHandler(ExecuteAsync);
|
||||
}
|
||||
|
||||
private async Task ExecuteAsync()
|
||||
{
|
||||
await Bash.ExecuteAsync([
|
||||
"source .venv/bin/activate",
|
||||
"uvicorn main:app --reload"
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
37
MycroForge.CLI/Commands/MycroForge.Entity.Link.Many.cs
Normal file
37
MycroForge.CLI/Commands/MycroForge.Entity.Link.Many.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
using System.CommandLine;
|
||||
using MycroForge.CLI.Commands.Interfaces;
|
||||
|
||||
namespace MycroForge.CLI.Commands;
|
||||
|
||||
public partial class MycroForge
|
||||
{
|
||||
public partial class Entity
|
||||
{
|
||||
public partial class Link
|
||||
{
|
||||
public class Many : Command, ISubCommandOf<Link>
|
||||
{
|
||||
private static readonly Argument<string> NameArgument =
|
||||
new(name: "primary", description: "The left side of the relation");
|
||||
|
||||
private static readonly Option<string> ToOneOption =
|
||||
new(name: "--to-one", description: "The right side of the relation");
|
||||
|
||||
private static readonly Option<string> ToManyOption =
|
||||
new(name: "--to-many", description: "The right side of the relation");
|
||||
|
||||
public Many() : base("many", "Define a n:m relation")
|
||||
{
|
||||
AddArgument(NameArgument);
|
||||
AddOption(ToOneOption);
|
||||
AddOption(ToManyOption);
|
||||
this.SetHandler(ExecuteAsync);
|
||||
}
|
||||
|
||||
private async Task ExecuteAsync()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
38
MycroForge.CLI/Commands/MycroForge.Entity.Link.One.cs
Normal file
38
MycroForge.CLI/Commands/MycroForge.Entity.Link.One.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
using System.CommandLine;
|
||||
using MycroForge.CLI.Commands.Interfaces;
|
||||
|
||||
namespace MycroForge.CLI.Commands;
|
||||
|
||||
public partial class MycroForge
|
||||
{
|
||||
public partial class Entity
|
||||
{
|
||||
public partial class Link
|
||||
{
|
||||
public class One : Command, ISubCommandOf<Link>
|
||||
{
|
||||
private static readonly Argument<string> NameArgument =
|
||||
new(name: "primary", description: "The left side of the relation");
|
||||
|
||||
private static readonly Option<string> ToOneOption =
|
||||
new(name: "--to-one", description: "The right side of the relation");
|
||||
|
||||
private static readonly Option<string> ToManyOption =
|
||||
new(name: "--to-many", description: "The right side of the relation");
|
||||
|
||||
|
||||
public One() : base("one", "Define a 1:n relation")
|
||||
{
|
||||
AddArgument(NameArgument);
|
||||
AddOption(ToOneOption);
|
||||
AddOption(ToManyOption);
|
||||
this.SetHandler(ExecuteAsync);
|
||||
}
|
||||
|
||||
private async Task ExecuteAsync()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
20
MycroForge.CLI/Commands/MycroForge.Entity.Link.cs
Normal file
20
MycroForge.CLI/Commands/MycroForge.Entity.Link.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
using System.CommandLine;
|
||||
using MycroForge.CLI.Commands.Interfaces;
|
||||
|
||||
namespace MycroForge.CLI.Commands;
|
||||
|
||||
public partial class MycroForge
|
||||
{
|
||||
public partial class Entity
|
||||
{
|
||||
public partial class Link : Command, ISubCommandOf<Entity>
|
||||
{
|
||||
public Link(IEnumerable<ISubCommandOf<Link>> commands) :
|
||||
base("link", "Define relationships between entities")
|
||||
{
|
||||
foreach (var command in commands)
|
||||
AddCommand((command as Command)!);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
17
MycroForge.CLI/Commands/MycroForge.Entity.cs
Normal file
17
MycroForge.CLI/Commands/MycroForge.Entity.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using System.CommandLine;
|
||||
using MycroForge.CLI.Commands.Interfaces;
|
||||
|
||||
namespace MycroForge.CLI.Commands;
|
||||
|
||||
public partial class MycroForge
|
||||
{
|
||||
public partial class Entity : Command, ISubCommandOf<MycroForge>
|
||||
{
|
||||
public Entity(IEnumerable<ISubCommandOf<Entity>> commands) :
|
||||
base("entity", "Manage the entities in your project")
|
||||
{
|
||||
foreach (var command in commands.Cast<Command>())
|
||||
AddCommand(command);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,19 +9,22 @@ public partial class MycroForge
|
||||
{
|
||||
public partial class Generate
|
||||
{
|
||||
// ReSharper disable once MemberHidesStaticFromOuterClass
|
||||
public class Entity : Command, ISubCommandOf<Generate>
|
||||
{
|
||||
private static readonly string[] Template =
|
||||
[
|
||||
"from sqlalchemy import INTEGER, Column, String",
|
||||
"from sqlalchemy import String",
|
||||
"from sqlalchemy.orm import Mapped, mapped_column",
|
||||
"from orm.entities.entity_base import EntityBase",
|
||||
"",
|
||||
"class %class_name%(EntityBase):",
|
||||
"\t__tablename__ = \"%table_name%\"",
|
||||
"\tid = Column(INTEGER, primary_key=True)",
|
||||
"\tid: Mapped[int] = mapped_column(primary_key=True)",
|
||||
"\tvalue: Mapped[str] = mapped_column(String(255))",
|
||||
"",
|
||||
"\tdef __repr__(self) -> str:",
|
||||
"\t\treturn f\"%class_name%(id={self.id!r})\""
|
||||
"\t\treturn f\"%class_name%(id={self.id!r}, value={self.value!r})\""
|
||||
];
|
||||
|
||||
private static readonly Argument<string> NameArgument =
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
using System.CommandLine;
|
||||
using MycroForge.CLI.Commands.Interfaces;
|
||||
|
||||
namespace MycroForge.CLI.Commands;
|
||||
|
||||
public partial class MycroForge
|
||||
{
|
||||
public class Rewrite : Command, ISubCommandOf<MycroForge>
|
||||
{
|
||||
public Rewrite() : base("rewrite", "Test a python source rewriter.")
|
||||
{
|
||||
this.SetHandler(ExecuteAsync);
|
||||
}
|
||||
|
||||
private async Task ExecuteAsync()
|
||||
{
|
||||
// var path = Path.Combine(Directory.GetCurrentDirectory(), "main.py");
|
||||
// var source = await File.ReadAllTextAsync(path);
|
||||
// var rewriter = new TestRewriter(source);
|
||||
// var rewrite = rewriter.Rewrite();
|
||||
// await File.WriteAllTextAsync(path, rewrite);
|
||||
}
|
||||
}
|
||||
}
|
||||
23
MycroForge.CLI/Commands/MycroForge.Run.cs
Normal file
23
MycroForge.CLI/Commands/MycroForge.Run.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using System.CommandLine;
|
||||
using MycroForge.CLI.Commands.Interfaces;
|
||||
|
||||
namespace MycroForge.CLI.Commands;
|
||||
|
||||
public partial class MycroForge
|
||||
{
|
||||
public class Run : Command, ISubCommandOf<MycroForge>
|
||||
{
|
||||
public Run() : base("run", "Run your app")
|
||||
{
|
||||
this.SetHandler(ExecuteAsync);
|
||||
}
|
||||
|
||||
private async Task ExecuteAsync()
|
||||
{
|
||||
await Bash.ExecuteAsync([
|
||||
"source .venv/bin/activate",
|
||||
"uvicorn main:app --reload"
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user