Making plugin system more robust

This commit is contained in:
mdnapo 2024-06-30 13:59:40 +02:00
parent f329b00687
commit c220c214d2
10 changed files with 124 additions and 0 deletions

View File

@ -0,0 +1,28 @@
using System.CommandLine;
using MycroForge.Core;
using MycroForge.Core.Contract;
namespace MycroForge.CLI.Commands;
public partial class MycroForge
{
public partial class Plugin
{
public class Init : Command, ISubCommandOf<Plugin>
{
private readonly ProjectContext _context;
public Init(ProjectContext context) : base("init", "Initialize a basic plugin project")
{
_context = context;
this.SetHandler(ExecuteAsync);
}
private void ExecuteAsync()
{
foreach (var plugin in Plugins.Loaded)
Console.WriteLine($"name: {plugin.Name}, command: {plugin.Command}");
}
}
}
}

View File

@ -4,6 +4,11 @@
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<PackageId>MycroForge.Core</PackageId>
<Version>1.0.0</Version>
<Authors>Donné Napo</Authors>
<Company>Dev Disciples</Company>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
</PropertyGroup>
<ItemGroup>

View File

@ -0,0 +1,5 @@
### Publish to local nuget repo
```shell
dotnet nuget push ./bin/Debug/MycroForge.Core.1.0.0.nupkg --source http://localhost:5555/v3/index.json --api-key password
```

View File

@ -0,0 +1,5 @@
namespace MycroForge.Plugin.Template.Package;
public class Class1
{
}

View File

@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>

View File

@ -0,0 +1,6 @@
namespace MycroForge.Plugin.Template;
public static class Constants
{
public const string MainCommandName = "mj";
}

View File

@ -0,0 +1,25 @@
using System.CommandLine;
using MycroForge.Core;
using MycroForge.Core.Contract;
using RootCommand = MycroForge.Core.RootCommand;
namespace MycroForge.Plugin.Template;
public class HelloWorldCommand : Command, ISubCommandOf<RootCommand>
{
private readonly ProjectContext _context;
public HelloWorldCommand(ProjectContext context) :
base(Constants.MainCommandName, "Custom command for My Jewellery specific stuff")
{
_context = context;
this.SetHandler(ExecuteAsync);
}
private async Task ExecuteAsync()
{
await _context.CreateFile("hello_world.txt",
"My Jewellery command plugin is working!"
);
}
}

View File

@ -0,0 +1,16 @@
using Microsoft.Extensions.DependencyInjection;
using MycroForge.Core.Contract;
using RootCommand = MycroForge.Core.RootCommand;
namespace MycroForge.Plugin.Template;
public class HelloWorldCommandPlugin : ICommandPlugin
{
public string Name => "MycroForge.Plugin.Template";
public string Command => Constants.MainCommandName;
public void RegisterServices(IServiceCollection services)
{
services.AddScoped<ISubCommandOf<RootCommand>, HelloWorldCommand>();
}
}

View File

@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="MycroForge.Core" Version="1.0.0" />
</ItemGroup>
</Project>

View File

@ -6,6 +6,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MycroForge.Core", "MycroFor
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MycroForge.TestPlugin", "MycroForge.TestPlugin\MycroForge.TestPlugin.csproj", "{7C479E68-98FA-4FBC-B5E4-7116015774B3}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MycroForge.Plugin.Template", "MycroForge.Plugin.Template\MycroForge.Plugin.Template.csproj", "{114A2B34-D77E-42AE-ADAF-0CD68C7B8D32}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MycroForge.Plugin.Template.Package", "MycroForge.Plugin.Template.Package\MycroForge.Plugin.Template.Package.csproj", "{FF110508-7D12-48DB-9484-8D2A0A5D29B8}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -24,5 +28,13 @@ Global
{7C479E68-98FA-4FBC-B5E4-7116015774B3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7C479E68-98FA-4FBC-B5E4-7116015774B3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7C479E68-98FA-4FBC-B5E4-7116015774B3}.Release|Any CPU.Build.0 = Release|Any CPU
{114A2B34-D77E-42AE-ADAF-0CD68C7B8D32}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{114A2B34-D77E-42AE-ADAF-0CD68C7B8D32}.Debug|Any CPU.Build.0 = Debug|Any CPU
{114A2B34-D77E-42AE-ADAF-0CD68C7B8D32}.Release|Any CPU.ActiveCfg = Release|Any CPU
{114A2B34-D77E-42AE-ADAF-0CD68C7B8D32}.Release|Any CPU.Build.0 = Release|Any CPU
{FF110508-7D12-48DB-9484-8D2A0A5D29B8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FF110508-7D12-48DB-9484-8D2A0A5D29B8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FF110508-7D12-48DB-9484-8D2A0A5D29B8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FF110508-7D12-48DB-9484-8D2A0A5D29B8}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal