From 3829eb0d7f30b8b7a70c33cc45729f1e95ea41c8 Mon Sep 17 00:00:00 2001 From: mdnapo Date: Sat, 29 Jun 2024 12:59:13 +0200 Subject: [PATCH] Replaced scripting system with plugin system --- MycroForge.CLI/CodeGen/CrudRouterGenerator.cs | 1 + .../CodeGen/CrudServiceGenerator.cs | 1 + MycroForge.CLI/CodeGen/DbEnvInitializer.cs | 4 +- MycroForge.CLI/CodeGen/DbEnvModifier.cs | 4 +- .../CodeGen/EntityLinker.EntityModel.cs | 1 + MycroForge.CLI/CodeGen/EntityLinker.cs | 1 + MycroForge.CLI/CodeGen/MainModifier.cs | 4 +- .../CodeGen/RequestClassGenerator.cs | 1 + .../Commands/MycroForge.Api.Generate.Crud.cs | 3 +- .../MycroForge.Api.Generate.Router.cs | 3 +- .../Commands/MycroForge.Api.Generate.cs | 2 +- MycroForge.CLI/Commands/MycroForge.Api.Run.cs | 3 +- MycroForge.CLI/Commands/MycroForge.Api.cs | 2 +- .../Commands/MycroForge.Db.Generate.Entity.cs | 3 +- .../MycroForge.Db.Generate.Migration.cs | 3 +- .../Commands/MycroForge.Db.Generate.cs | 2 +- .../Commands/MycroForge.Db.Link.Many.cs | 3 +- .../Commands/MycroForge.Db.Link.One.cs | 3 +- MycroForge.CLI/Commands/MycroForge.Db.Link.cs | 2 +- .../Commands/MycroForge.Db.Migrate.cs | 3 +- .../Commands/MycroForge.Db.Rollback.cs | 3 +- MycroForge.CLI/Commands/MycroForge.Db.Run.cs | 3 +- MycroForge.CLI/Commands/MycroForge.Db.Stop.cs | 3 +- MycroForge.CLI/Commands/MycroForge.Db.cs | 2 +- .../Commands/MycroForge.Generate.Service.cs | 3 +- .../Commands/MycroForge.Generate.Venv.cs | 3 +- .../Commands/MycroForge.Generate.cs | 2 +- MycroForge.CLI/Commands/MycroForge.Hydrate.cs | 3 +- MycroForge.CLI/Commands/MycroForge.Init.cs | 5 +- MycroForge.CLI/Commands/MycroForge.Install.cs | 3 +- .../Commands/MycroForge.Plugin.Install.cs | 68 +++++++++++++++ .../Commands/MycroForge.Plugin.List.cs | 26 ++++++ .../Commands/MycroForge.Plugin.Uninstall.cs | 43 ++++++++++ MycroForge.CLI/Commands/MycroForge.Plugin.cs | 18 ++++ .../Commands/MycroForge.Script.Create.cs | 65 --------------- .../Commands/MycroForge.Script.Edit.cs | 55 ------------- .../Commands/MycroForge.Script.List.cs | 32 -------- .../Commands/MycroForge.Script.Run.cs | 82 ------------------- MycroForge.CLI/Commands/MycroForge.Script.cs | 18 ---- .../Commands/MycroForge.Uninstall.cs | 3 +- MycroForge.CLI/Commands/MycroForge.cs | 17 ++-- MycroForge.CLI/Commands/Plugins.cs | 57 +++++++++++++ .../Extensions/ServiceCollectionExtensions.cs | 29 +++++-- MycroForge.CLI/Features/Api.cs | 4 +- MycroForge.CLI/Features/Db.cs | 1 + MycroForge.CLI/Features/Git.cs | 2 + MycroForge.CLI/Features/IFeature.cs | 4 +- MycroForge.CLI/MycroForge.CLI.csproj | 4 +- MycroForge.CLI/Program.cs | 8 +- .../CodeGen/Source.cs | 2 +- .../CodeGen/SourceMatch.cs | 2 +- MycroForge.Core/Contract/ICommandPlugin.cs | 11 +++ .../Contract}/ISubCommandOf.cs | 2 +- .../Extensions/ObjectStreamExtensions.cs | 4 +- MycroForge.Core/MycroForge.Core.csproj | 24 ++++-- .../ProjectConfig.ApiConfig.cs | 2 +- .../ProjectConfig.DbConfig.cs | 2 +- .../ProjectConfig.cs | 2 +- .../ProjectContext.cs | 10 +-- MycroForge.Core/RootCommand.cs | 8 ++ .../Serialization.cs | 4 +- MycroForge.TestPlugin/Constants.cs | 6 ++ MycroForge.TestPlugin/MyJewelleryCommand.cs | 25 ++++++ .../MyJewelleryCommandPlugin.cs | 16 ++++ .../MycroForge.TestPlugin.csproj | 13 +++ MycroForge.sln | 6 ++ 66 files changed, 431 insertions(+), 323 deletions(-) create mode 100644 MycroForge.CLI/Commands/MycroForge.Plugin.Install.cs create mode 100644 MycroForge.CLI/Commands/MycroForge.Plugin.List.cs create mode 100644 MycroForge.CLI/Commands/MycroForge.Plugin.Uninstall.cs create mode 100644 MycroForge.CLI/Commands/MycroForge.Plugin.cs delete mode 100644 MycroForge.CLI/Commands/MycroForge.Script.Create.cs delete mode 100644 MycroForge.CLI/Commands/MycroForge.Script.Edit.cs delete mode 100644 MycroForge.CLI/Commands/MycroForge.Script.List.cs delete mode 100644 MycroForge.CLI/Commands/MycroForge.Script.Run.cs delete mode 100644 MycroForge.CLI/Commands/MycroForge.Script.cs create mode 100644 MycroForge.CLI/Commands/Plugins.cs rename {MycroForge.CLI => MycroForge.Core}/CodeGen/Source.cs (94%) rename {MycroForge.CLI => MycroForge.Core}/CodeGen/SourceMatch.cs (84%) create mode 100644 MycroForge.Core/Contract/ICommandPlugin.cs rename {MycroForge.CLI/Commands/Interfaces => MycroForge.Core/Contract}/ISubCommandOf.cs (62%) rename {MycroForge.CLI => MycroForge.Core}/Extensions/ObjectStreamExtensions.cs (75%) rename {MycroForge.CLI => MycroForge.Core}/ProjectConfig.ApiConfig.cs (75%) rename {MycroForge.CLI => MycroForge.Core}/ProjectConfig.DbConfig.cs (80%) rename {MycroForge.CLI => MycroForge.Core}/ProjectConfig.cs (79%) rename {MycroForge.CLI => MycroForge.Core}/ProjectContext.cs (90%) create mode 100644 MycroForge.Core/RootCommand.cs rename MycroForge.CLI/Shared.cs => MycroForge.Core/Serialization.cs (85%) create mode 100644 MycroForge.TestPlugin/Constants.cs create mode 100644 MycroForge.TestPlugin/MyJewelleryCommand.cs create mode 100644 MycroForge.TestPlugin/MyJewelleryCommandPlugin.cs create mode 100644 MycroForge.TestPlugin/MycroForge.TestPlugin.csproj diff --git a/MycroForge.CLI/CodeGen/CrudRouterGenerator.cs b/MycroForge.CLI/CodeGen/CrudRouterGenerator.cs index 336bc7a..9108c6b 100644 --- a/MycroForge.CLI/CodeGen/CrudRouterGenerator.cs +++ b/MycroForge.CLI/CodeGen/CrudRouterGenerator.cs @@ -1,5 +1,6 @@ using Humanizer; using MycroForge.CLI.Extensions; +using MycroForge.Core; namespace MycroForge.CLI.CodeGen; diff --git a/MycroForge.CLI/CodeGen/CrudServiceGenerator.cs b/MycroForge.CLI/CodeGen/CrudServiceGenerator.cs index da28915..8341790 100644 --- a/MycroForge.CLI/CodeGen/CrudServiceGenerator.cs +++ b/MycroForge.CLI/CodeGen/CrudServiceGenerator.cs @@ -1,5 +1,6 @@ using Humanizer; using MycroForge.CLI.Extensions; +using MycroForge.Core; namespace MycroForge.CLI.CodeGen; diff --git a/MycroForge.CLI/CodeGen/DbEnvInitializer.cs b/MycroForge.CLI/CodeGen/DbEnvInitializer.cs index 383d4c0..21b95d5 100644 --- a/MycroForge.CLI/CodeGen/DbEnvInitializer.cs +++ b/MycroForge.CLI/CodeGen/DbEnvInitializer.cs @@ -1,4 +1,6 @@ -namespace MycroForge.CLI.CodeGen; +using MycroForge.Core.CodeGen; + +namespace MycroForge.CLI.CodeGen; public class DbEnvInitializer { diff --git a/MycroForge.CLI/CodeGen/DbEnvModifier.cs b/MycroForge.CLI/CodeGen/DbEnvModifier.cs index 1e11d6f..eea9129 100644 --- a/MycroForge.CLI/CodeGen/DbEnvModifier.cs +++ b/MycroForge.CLI/CodeGen/DbEnvModifier.cs @@ -1,4 +1,6 @@ -namespace MycroForge.CLI.CodeGen; +using MycroForge.Core.CodeGen; + +namespace MycroForge.CLI.CodeGen; public class DbEnvModifier { diff --git a/MycroForge.CLI/CodeGen/EntityLinker.EntityModel.cs b/MycroForge.CLI/CodeGen/EntityLinker.EntityModel.cs index dff280f..50a5887 100644 --- a/MycroForge.CLI/CodeGen/EntityLinker.EntityModel.cs +++ b/MycroForge.CLI/CodeGen/EntityLinker.EntityModel.cs @@ -1,4 +1,5 @@ using Humanizer; +using MycroForge.Core.CodeGen; namespace MycroForge.CLI.CodeGen; diff --git a/MycroForge.CLI/CodeGen/EntityLinker.cs b/MycroForge.CLI/CodeGen/EntityLinker.cs index 005b8ff..8c7feb0 100644 --- a/MycroForge.CLI/CodeGen/EntityLinker.cs +++ b/MycroForge.CLI/CodeGen/EntityLinker.cs @@ -1,4 +1,5 @@ using Humanizer; +using MycroForge.Core; namespace MycroForge.CLI.CodeGen; diff --git a/MycroForge.CLI/CodeGen/MainModifier.cs b/MycroForge.CLI/CodeGen/MainModifier.cs index bf3ace6..082b781 100644 --- a/MycroForge.CLI/CodeGen/MainModifier.cs +++ b/MycroForge.CLI/CodeGen/MainModifier.cs @@ -1,4 +1,6 @@ -namespace MycroForge.CLI.CodeGen; +using MycroForge.Core.CodeGen; + +namespace MycroForge.CLI.CodeGen; public class MainModifier { diff --git a/MycroForge.CLI/CodeGen/RequestClassGenerator.cs b/MycroForge.CLI/CodeGen/RequestClassGenerator.cs index 96ae6d3..32df4fd 100644 --- a/MycroForge.CLI/CodeGen/RequestClassGenerator.cs +++ b/MycroForge.CLI/CodeGen/RequestClassGenerator.cs @@ -1,5 +1,6 @@ using System.Text.RegularExpressions; using Humanizer; +using MycroForge.Core; namespace MycroForge.CLI.CodeGen; diff --git a/MycroForge.CLI/Commands/MycroForge.Api.Generate.Crud.cs b/MycroForge.CLI/Commands/MycroForge.Api.Generate.Crud.cs index 2600932..c9a1275 100644 --- a/MycroForge.CLI/Commands/MycroForge.Api.Generate.Crud.cs +++ b/MycroForge.CLI/Commands/MycroForge.Api.Generate.Crud.cs @@ -1,6 +1,7 @@ using System.CommandLine; using MycroForge.CLI.CodeGen; -using MycroForge.CLI.Commands.Interfaces; +using MycroForge.Core; +using MycroForge.Core.Contract; namespace MycroForge.CLI.Commands; diff --git a/MycroForge.CLI/Commands/MycroForge.Api.Generate.Router.cs b/MycroForge.CLI/Commands/MycroForge.Api.Generate.Router.cs index 9a8ce10..7a20e64 100644 --- a/MycroForge.CLI/Commands/MycroForge.Api.Generate.Router.cs +++ b/MycroForge.CLI/Commands/MycroForge.Api.Generate.Router.cs @@ -1,7 +1,8 @@ using System.CommandLine; using Humanizer; -using MycroForge.CLI.Commands.Interfaces; +using MycroForge.Core.Contract; using MycroForge.CLI.Extensions; +using MycroForge.Core; namespace MycroForge.CLI.Commands; diff --git a/MycroForge.CLI/Commands/MycroForge.Api.Generate.cs b/MycroForge.CLI/Commands/MycroForge.Api.Generate.cs index 889274e..e079029 100644 --- a/MycroForge.CLI/Commands/MycroForge.Api.Generate.cs +++ b/MycroForge.CLI/Commands/MycroForge.Api.Generate.cs @@ -1,5 +1,5 @@ using System.CommandLine; -using MycroForge.CLI.Commands.Interfaces; +using MycroForge.Core.Contract; namespace MycroForge.CLI.Commands; diff --git a/MycroForge.CLI/Commands/MycroForge.Api.Run.cs b/MycroForge.CLI/Commands/MycroForge.Api.Run.cs index f1d86bb..011a29b 100644 --- a/MycroForge.CLI/Commands/MycroForge.Api.Run.cs +++ b/MycroForge.CLI/Commands/MycroForge.Api.Run.cs @@ -1,5 +1,6 @@ using System.CommandLine; -using MycroForge.CLI.Commands.Interfaces; +using MycroForge.Core; +using MycroForge.Core.Contract; namespace MycroForge.CLI.Commands; diff --git a/MycroForge.CLI/Commands/MycroForge.Api.cs b/MycroForge.CLI/Commands/MycroForge.Api.cs index 8a14aef..5580a3c 100644 --- a/MycroForge.CLI/Commands/MycroForge.Api.cs +++ b/MycroForge.CLI/Commands/MycroForge.Api.cs @@ -1,5 +1,5 @@ using System.CommandLine; -using MycroForge.CLI.Commands.Interfaces; +using MycroForge.Core.Contract; namespace MycroForge.CLI.Commands; diff --git a/MycroForge.CLI/Commands/MycroForge.Db.Generate.Entity.cs b/MycroForge.CLI/Commands/MycroForge.Db.Generate.Entity.cs index 1d82d80..e0ab45b 100644 --- a/MycroForge.CLI/Commands/MycroForge.Db.Generate.Entity.cs +++ b/MycroForge.CLI/Commands/MycroForge.Db.Generate.Entity.cs @@ -1,8 +1,9 @@ using System.CommandLine; using Humanizer; using MycroForge.CLI.CodeGen; -using MycroForge.CLI.Commands.Interfaces; +using MycroForge.Core.Contract; using MycroForge.CLI.Extensions; +using MycroForge.Core; namespace MycroForge.CLI.Commands; diff --git a/MycroForge.CLI/Commands/MycroForge.Db.Generate.Migration.cs b/MycroForge.CLI/Commands/MycroForge.Db.Generate.Migration.cs index 89aec3a..a559912 100644 --- a/MycroForge.CLI/Commands/MycroForge.Db.Generate.Migration.cs +++ b/MycroForge.CLI/Commands/MycroForge.Db.Generate.Migration.cs @@ -1,5 +1,6 @@ using System.CommandLine; -using MycroForge.CLI.Commands.Interfaces; +using MycroForge.Core; +using MycroForge.Core.Contract; namespace MycroForge.CLI.Commands; diff --git a/MycroForge.CLI/Commands/MycroForge.Db.Generate.cs b/MycroForge.CLI/Commands/MycroForge.Db.Generate.cs index 8404291..6ef17cd 100644 --- a/MycroForge.CLI/Commands/MycroForge.Db.Generate.cs +++ b/MycroForge.CLI/Commands/MycroForge.Db.Generate.cs @@ -1,5 +1,5 @@ using System.CommandLine; -using MycroForge.CLI.Commands.Interfaces; +using MycroForge.Core.Contract; namespace MycroForge.CLI.Commands; diff --git a/MycroForge.CLI/Commands/MycroForge.Db.Link.Many.cs b/MycroForge.CLI/Commands/MycroForge.Db.Link.Many.cs index 8945a33..a969fa1 100644 --- a/MycroForge.CLI/Commands/MycroForge.Db.Link.Many.cs +++ b/MycroForge.CLI/Commands/MycroForge.Db.Link.Many.cs @@ -1,6 +1,7 @@ using System.CommandLine; using MycroForge.CLI.CodeGen; -using MycroForge.CLI.Commands.Interfaces; +using MycroForge.Core; +using MycroForge.Core.Contract; namespace MycroForge.CLI.Commands; diff --git a/MycroForge.CLI/Commands/MycroForge.Db.Link.One.cs b/MycroForge.CLI/Commands/MycroForge.Db.Link.One.cs index 1471e26..4412f2d 100644 --- a/MycroForge.CLI/Commands/MycroForge.Db.Link.One.cs +++ b/MycroForge.CLI/Commands/MycroForge.Db.Link.One.cs @@ -1,6 +1,7 @@ using System.CommandLine; using MycroForge.CLI.CodeGen; -using MycroForge.CLI.Commands.Interfaces; +using MycroForge.Core; +using MycroForge.Core.Contract; namespace MycroForge.CLI.Commands; diff --git a/MycroForge.CLI/Commands/MycroForge.Db.Link.cs b/MycroForge.CLI/Commands/MycroForge.Db.Link.cs index c46abe4..8b448df 100644 --- a/MycroForge.CLI/Commands/MycroForge.Db.Link.cs +++ b/MycroForge.CLI/Commands/MycroForge.Db.Link.cs @@ -1,5 +1,5 @@ using System.CommandLine; -using MycroForge.CLI.Commands.Interfaces; +using MycroForge.Core.Contract; namespace MycroForge.CLI.Commands; diff --git a/MycroForge.CLI/Commands/MycroForge.Db.Migrate.cs b/MycroForge.CLI/Commands/MycroForge.Db.Migrate.cs index fc6b214..500be02 100644 --- a/MycroForge.CLI/Commands/MycroForge.Db.Migrate.cs +++ b/MycroForge.CLI/Commands/MycroForge.Db.Migrate.cs @@ -1,5 +1,6 @@ using System.CommandLine; -using MycroForge.CLI.Commands.Interfaces; +using MycroForge.Core; +using MycroForge.Core.Contract; namespace MycroForge.CLI.Commands; diff --git a/MycroForge.CLI/Commands/MycroForge.Db.Rollback.cs b/MycroForge.CLI/Commands/MycroForge.Db.Rollback.cs index 4e66c3a..ac2b043 100644 --- a/MycroForge.CLI/Commands/MycroForge.Db.Rollback.cs +++ b/MycroForge.CLI/Commands/MycroForge.Db.Rollback.cs @@ -1,5 +1,6 @@ using System.CommandLine; -using MycroForge.CLI.Commands.Interfaces; +using MycroForge.Core; +using MycroForge.Core.Contract; namespace MycroForge.CLI.Commands; diff --git a/MycroForge.CLI/Commands/MycroForge.Db.Run.cs b/MycroForge.CLI/Commands/MycroForge.Db.Run.cs index ef8ced0..b455876 100644 --- a/MycroForge.CLI/Commands/MycroForge.Db.Run.cs +++ b/MycroForge.CLI/Commands/MycroForge.Db.Run.cs @@ -1,5 +1,6 @@ using System.CommandLine; -using MycroForge.CLI.Commands.Interfaces; +using MycroForge.Core; +using MycroForge.Core.Contract; namespace MycroForge.CLI.Commands; diff --git a/MycroForge.CLI/Commands/MycroForge.Db.Stop.cs b/MycroForge.CLI/Commands/MycroForge.Db.Stop.cs index cd835cd..2ca7cd2 100644 --- a/MycroForge.CLI/Commands/MycroForge.Db.Stop.cs +++ b/MycroForge.CLI/Commands/MycroForge.Db.Stop.cs @@ -1,5 +1,6 @@ using System.CommandLine; -using MycroForge.CLI.Commands.Interfaces; +using MycroForge.Core; +using MycroForge.Core.Contract; namespace MycroForge.CLI.Commands; diff --git a/MycroForge.CLI/Commands/MycroForge.Db.cs b/MycroForge.CLI/Commands/MycroForge.Db.cs index aa25061..7b8cc99 100644 --- a/MycroForge.CLI/Commands/MycroForge.Db.cs +++ b/MycroForge.CLI/Commands/MycroForge.Db.cs @@ -1,5 +1,5 @@ using System.CommandLine; -using MycroForge.CLI.Commands.Interfaces; +using MycroForge.Core.Contract; namespace MycroForge.CLI.Commands; diff --git a/MycroForge.CLI/Commands/MycroForge.Generate.Service.cs b/MycroForge.CLI/Commands/MycroForge.Generate.Service.cs index 898ddcc..605bba2 100644 --- a/MycroForge.CLI/Commands/MycroForge.Generate.Service.cs +++ b/MycroForge.CLI/Commands/MycroForge.Generate.Service.cs @@ -1,7 +1,8 @@ using System.CommandLine; using Humanizer; -using MycroForge.CLI.Commands.Interfaces; +using MycroForge.Core.Contract; using MycroForge.CLI.Extensions; +using MycroForge.Core; namespace MycroForge.CLI.Commands; diff --git a/MycroForge.CLI/Commands/MycroForge.Generate.Venv.cs b/MycroForge.CLI/Commands/MycroForge.Generate.Venv.cs index bbda063..f33ea96 100644 --- a/MycroForge.CLI/Commands/MycroForge.Generate.Venv.cs +++ b/MycroForge.CLI/Commands/MycroForge.Generate.Venv.cs @@ -1,5 +1,6 @@ using System.CommandLine; -using MycroForge.CLI.Commands.Interfaces; +using MycroForge.Core; +using MycroForge.Core.Contract; namespace MycroForge.CLI.Commands; diff --git a/MycroForge.CLI/Commands/MycroForge.Generate.cs b/MycroForge.CLI/Commands/MycroForge.Generate.cs index 9cf7e52..c4f4478 100644 --- a/MycroForge.CLI/Commands/MycroForge.Generate.cs +++ b/MycroForge.CLI/Commands/MycroForge.Generate.cs @@ -1,5 +1,5 @@ using System.CommandLine; -using MycroForge.CLI.Commands.Interfaces; +using MycroForge.Core.Contract; namespace MycroForge.CLI.Commands; diff --git a/MycroForge.CLI/Commands/MycroForge.Hydrate.cs b/MycroForge.CLI/Commands/MycroForge.Hydrate.cs index 8d770c6..bdbbd9d 100644 --- a/MycroForge.CLI/Commands/MycroForge.Hydrate.cs +++ b/MycroForge.CLI/Commands/MycroForge.Hydrate.cs @@ -1,5 +1,6 @@ using System.CommandLine; -using MycroForge.CLI.Commands.Interfaces; +using MycroForge.Core; +using MycroForge.Core.Contract; namespace MycroForge.CLI.Commands; diff --git a/MycroForge.CLI/Commands/MycroForge.Init.cs b/MycroForge.CLI/Commands/MycroForge.Init.cs index b06f2a5..9417294 100644 --- a/MycroForge.CLI/Commands/MycroForge.Init.cs +++ b/MycroForge.CLI/Commands/MycroForge.Init.cs @@ -1,6 +1,7 @@ using System.CommandLine; -using MycroForge.CLI.Commands.Interfaces; +using MycroForge.Core.Contract; using MycroForge.CLI.Features; +using MycroForge.Core; namespace MycroForge.CLI.Commands; @@ -95,7 +96,7 @@ public partial class MycroForge // Create the project directory and change the directory for the ProjectContext var projectRoot = await CreateDirectory(name); - _context.ChangeDirectory(projectRoot); + _context.ChangeRootDirectory(projectRoot); // Create the config file and initialize the config await _context.CreateFile("m4g.json", "{}"); diff --git a/MycroForge.CLI/Commands/MycroForge.Install.cs b/MycroForge.CLI/Commands/MycroForge.Install.cs index 7ccb461..9a0ea9b 100644 --- a/MycroForge.CLI/Commands/MycroForge.Install.cs +++ b/MycroForge.CLI/Commands/MycroForge.Install.cs @@ -1,5 +1,6 @@ using System.CommandLine; -using MycroForge.CLI.Commands.Interfaces; +using MycroForge.Core; +using MycroForge.Core.Contract; namespace MycroForge.CLI.Commands; diff --git a/MycroForge.CLI/Commands/MycroForge.Plugin.Install.cs b/MycroForge.CLI/Commands/MycroForge.Plugin.Install.cs new file mode 100644 index 0000000..d6f75db --- /dev/null +++ b/MycroForge.CLI/Commands/MycroForge.Plugin.Install.cs @@ -0,0 +1,68 @@ +using System.CommandLine; +using Humanizer; +using Microsoft.Extensions.FileSystemGlobbing; +using Microsoft.Extensions.FileSystemGlobbing.Abstractions; +using MycroForge.Core; +using MycroForge.Core.Contract; + +namespace MycroForge.CLI.Commands; + +public partial class MycroForge +{ + public partial class Plugin + { + public class Install : Command, ISubCommandOf + { + public enum TargetPlatform + { + linux_arm, + linux_arm64, + linux_x64, + osx_arm64, + osx_x64, + } + + private static readonly Option PlatformOption = new( + aliases: ["-p", "--platform"], + description: "The platform to target when building the plugin" + ) { IsRequired = true }; + + private readonly ProjectContext _context; + + public Install(ProjectContext context) : base("install", "Install a plugin") + { + _context = context; + AddAlias("i"); + AddOption(PlatformOption); + this.SetHandler(ExecuteAsync, PlatformOption); + } + + private async Task ExecuteAsync(TargetPlatform target) + { + var assemblyName = GetAssemblyName(); + var pluginInstallPath = Path.Join(Plugins.RootDirectory, assemblyName); + var platform = target.ToString().Dasherize(); + await _context.Bash($"dotnet publish -c Release -r {platform} --output {pluginInstallPath}"); + Console.WriteLine($"Successfully installed plugin {assemblyName}"); + + } + + private string GetAssemblyName() + { + var matcher = new Matcher().AddInclude("*.csproj"); + var currentDirectory = Environment.CurrentDirectory; + + var result = matcher.Execute( + new DirectoryInfoWrapper( + new DirectoryInfo(currentDirectory) + ) + ); + + if (!result.HasMatches) + throw new Exception($"Could not find .csproj file in directory {currentDirectory}"); + + return Path.GetFileNameWithoutExtension(result.Files.First().Path); + } + } + } +} \ No newline at end of file diff --git a/MycroForge.CLI/Commands/MycroForge.Plugin.List.cs b/MycroForge.CLI/Commands/MycroForge.Plugin.List.cs new file mode 100644 index 0000000..56324b0 --- /dev/null +++ b/MycroForge.CLI/Commands/MycroForge.Plugin.List.cs @@ -0,0 +1,26 @@ +using System.CommandLine; +using MycroForge.Core.Contract; + +namespace MycroForge.CLI.Commands; + +public partial class MycroForge +{ + public partial class Plugin + { + public class List : Command, ISubCommandOf + { + public List() : base("list", "List all installed plugins") + { + AddAlias("l"); + AddAlias("ls"); + this.SetHandler(ExecuteAsync); + } + + private void ExecuteAsync() + { + foreach (var plugin in Plugins.Loaded) + Console.WriteLine($"name: {plugin.Name}, command: {plugin.Command}"); + } + } + } +} \ No newline at end of file diff --git a/MycroForge.CLI/Commands/MycroForge.Plugin.Uninstall.cs b/MycroForge.CLI/Commands/MycroForge.Plugin.Uninstall.cs new file mode 100644 index 0000000..7514f9a --- /dev/null +++ b/MycroForge.CLI/Commands/MycroForge.Plugin.Uninstall.cs @@ -0,0 +1,43 @@ +using System.CommandLine; +using MycroForge.Core.Contract; + +namespace MycroForge.CLI.Commands; + +public partial class MycroForge +{ + public partial class Plugin + { + public class Uninstall : Command, ISubCommandOf + { + private static readonly Argument> NamesArgument = new( + name: "name", + description: "The names of the plugins you want to uninstall" + ); + + public Uninstall() : base("uninstall", "Uninstall a plugin") + { + AddAlias("u"); + AddArgument(NamesArgument); + this.SetHandler(ExecuteAsync, NamesArgument); + } + + private void ExecuteAsync(IEnumerable names) + { + foreach (var name in names) + { + var dir = Path.Join(Plugins.RootDirectory, name); + + if (Directory.Exists(dir)) + { + Directory.Delete(dir, true); + Console.WriteLine($"Successfully uninstalled plugin {name}"); + } + else + { + Console.WriteLine($"Plugin {name} could not be found"); + } + } + } + } + } +} \ No newline at end of file diff --git a/MycroForge.CLI/Commands/MycroForge.Plugin.cs b/MycroForge.CLI/Commands/MycroForge.Plugin.cs new file mode 100644 index 0000000..2788fa8 --- /dev/null +++ b/MycroForge.CLI/Commands/MycroForge.Plugin.cs @@ -0,0 +1,18 @@ +using System.CommandLine; +using MycroForge.Core.Contract; + +namespace MycroForge.CLI.Commands; + +public partial class MycroForge +{ + public partial class Plugin : Command, ISubCommandOf + { + public Plugin(IEnumerable> commands) : + base("plugin", "Plugin related commands") + { + AddAlias("p"); + foreach (var command in commands.Cast()) + AddCommand(command); + } + } +} \ No newline at end of file diff --git a/MycroForge.CLI/Commands/MycroForge.Script.Create.cs b/MycroForge.CLI/Commands/MycroForge.Script.Create.cs deleted file mode 100644 index e44ee9c..0000000 --- a/MycroForge.CLI/Commands/MycroForge.Script.Create.cs +++ /dev/null @@ -1,65 +0,0 @@ -using System.CommandLine; -using System.Diagnostics; -using MycroForge.CLI.Commands.Interfaces; - -namespace MycroForge.CLI.Commands; - -public partial class MycroForge -{ - public partial class Script - { - public class Create : Command, ISubCommandOf