Improved plugin feature
This commit is contained in:
@@ -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"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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!"
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -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>();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user