Improved plugin feature
All checks were successful
Build and publish MycroForge.CLI / test (push) Has been skipped
Test MycroForge.CLI / test (push) Successful in 5m39s

This commit is contained in:
2024-10-13 13:39:56 +02:00
parent 8f82360cc7
commit 457429f7ec
6 changed files with 42 additions and 17 deletions

View File

@@ -17,5 +17,16 @@
"language": "C#",
"type": "project"
},
"preferNameDirectory": true
"preferNameDirectory": true,
"symbols": {
"class": {
"type": "parameter",
"replaces": "ExampleCommand",
"fileRename": "ExampleCommand"
},
"command": {
"type": "parameter",
"replaces": "example"
}
}
}

View File

@@ -5,7 +5,7 @@ using RootCommand = MycroForge.Core.RootCommand;
namespace MycroForge.PluginTemplate;
public class HelloWorldCommand : Command, ISubCommandOf<RootCommand>
public class ExampleCommand : Command, ISubCommandOf<RootCommand>
{
private readonly Argument<string> NameArgument =
new(name: "name", description: "The name of the person to greet");
@@ -15,8 +15,8 @@ public class HelloWorldCommand : Command, ISubCommandOf<RootCommand>
private readonly ProjectContext _context;
public HelloWorldCommand(ProjectContext context) :
base("hello", "An example command generated by dotnet new using the m4gp template")
public ExampleCommand(ProjectContext context) :
base("example", "A basic command plugin generated by the 'm4g plugin init' command")
{
_context = context;
AddArgument(NameArgument);
@@ -28,9 +28,9 @@ public class HelloWorldCommand : Command, ISubCommandOf<RootCommand>
{
name = allCaps ? name.ToUpper() : name;
await _context.CreateFile("hello_world.txt",
await _context.CreateFile("example.txt",
$"Hello {name}!",
"This file was generated by your custom command!"
"This file was generated by the 'm4g example' command!"
);
}
}

View File

@@ -4,12 +4,12 @@ using RootCommand = MycroForge.Core.RootCommand;
namespace MycroForge.PluginTemplate;
public class HelloWorldCommandPlugin : ICommandPlugin
public class ExampleCommandPlugin : ICommandPlugin
{
public string Name => "MycroForge.PluginTemplate";
public void RegisterServices(IServiceCollection services)
{
services.AddScoped<ISubCommandOf<RootCommand>, HelloWorldCommand>();
services.AddScoped<ISubCommandOf<RootCommand>, ExampleCommand>();
}
}