Making plugin system more robust
This commit is contained in:
6
MycroForge.Plugin.Template/Constants.cs
Normal file
6
MycroForge.Plugin.Template/Constants.cs
Normal file
@@ -0,0 +1,6 @@
|
||||
namespace MycroForge.Plugin.Template;
|
||||
|
||||
public static class Constants
|
||||
{
|
||||
public const string MainCommandName = "mj";
|
||||
}
|
||||
25
MycroForge.Plugin.Template/HelloWorldCommand.cs
Normal file
25
MycroForge.Plugin.Template/HelloWorldCommand.cs
Normal 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!"
|
||||
);
|
||||
}
|
||||
}
|
||||
16
MycroForge.Plugin.Template/HelloWorldCommandPlugin.cs
Normal file
16
MycroForge.Plugin.Template/HelloWorldCommandPlugin.cs
Normal 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>();
|
||||
}
|
||||
}
|
||||
13
MycroForge.Plugin.Template/MycroForge.Plugin.Template.csproj
Normal file
13
MycroForge.Plugin.Template/MycroForge.Plugin.Template.csproj
Normal 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>
|
||||
Reference in New Issue
Block a user