diff --git a/MycroForge.CLI/Commands/MycroForge.Plugin.Init.cs b/MycroForge.CLI/Commands/MycroForge.Plugin.Init.cs index 8ee95ea..5d7eb7a 100644 --- a/MycroForge.CLI/Commands/MycroForge.Plugin.Init.cs +++ b/MycroForge.CLI/Commands/MycroForge.Plugin.Init.cs @@ -10,21 +10,29 @@ public partial class MycroForge { public class Init : Command, ISubCommandOf { - private static readonly Argument NameArgument = - new(name: "name", description: "The name of your project"); + private static readonly Argument NamespaceArgument = + new(name: "namespace", description: "The namespace of your project"); + + private static readonly Argument ClassArgument = + new(name: "class", description: "The class name of the generated command"); + + private static readonly Argument CommandArgument = + new(name: "command", description: "The command name that will be added to 'm4g'"); private readonly ProjectContext _context; public Init(ProjectContext context) : base("init", "Initialize a basic plugin project") { _context = context; - AddArgument(NameArgument); - this.SetHandler(ExecuteAsync, NameArgument); + AddArgument(NamespaceArgument); + AddArgument(ClassArgument); + AddArgument(CommandArgument); + this.SetHandler(ExecuteAsync, NamespaceArgument, ClassArgument, CommandArgument); } - private async Task ExecuteAsync(string name) + private async Task ExecuteAsync(string @namespace, string @class, string command) { - await _context.Bash($"dotnet new m4gp -n {name}"); + await _context.Bash($"dotnet new m4gp -n {@namespace} --class {@class} --command {command}"); } } } diff --git a/MycroForge.CLI/Commands/MycroForge.Plugin.Install.cs b/MycroForge.CLI/Commands/MycroForge.Plugin.Install.cs index 1ad3ebc..b874e34 100644 --- a/MycroForge.CLI/Commands/MycroForge.Plugin.Install.cs +++ b/MycroForge.CLI/Commands/MycroForge.Plugin.Install.cs @@ -44,9 +44,13 @@ public partial class MycroForge 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}"); + var exitCode = await _context.Bash( + $"dotnet publish -c Release -r {platform} --output {pluginInstallPath}" + ); + Console.WriteLine(exitCode == 0 + ? $"Successfully installed plugin {assemblyName}" + : $"Could not install {assemblyName}, process exited with code {exitCode}."); } private string GetAssemblyName() diff --git a/MycroForge.Core/ProjectContext.cs b/MycroForge.Core/ProjectContext.cs index 2b9bbf8..868da9c 100644 --- a/MycroForge.Core/ProjectContext.cs +++ b/MycroForge.Core/ProjectContext.cs @@ -70,7 +70,7 @@ public class ProjectContext Console.WriteLine($"Modified file {path}"); } - public async Task Bash(params string[] script) + public async Task Bash(params string[] script) { var info = new ProcessStartInfo { @@ -112,6 +112,8 @@ public class ProjectContext await process.WaitForExitAsync(); Environment.ExitCode = process.ExitCode; + + return process.ExitCode; } public async Task SaveConfig(ProjectConfig config) diff --git a/MycroForge.PluginTemplate/.template.config/template.json b/MycroForge.PluginTemplate/.template.config/template.json index 7a6825c..43b5259 100644 --- a/MycroForge.PluginTemplate/.template.config/template.json +++ b/MycroForge.PluginTemplate/.template.config/template.json @@ -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" + } + } } \ No newline at end of file diff --git a/MycroForge.PluginTemplate/HelloWorldCommand.cs b/MycroForge.PluginTemplate/ExampleCommand.cs similarity index 69% rename from MycroForge.PluginTemplate/HelloWorldCommand.cs rename to MycroForge.PluginTemplate/ExampleCommand.cs index f4eca18..08134c0 100644 --- a/MycroForge.PluginTemplate/HelloWorldCommand.cs +++ b/MycroForge.PluginTemplate/ExampleCommand.cs @@ -5,7 +5,7 @@ using RootCommand = MycroForge.Core.RootCommand; namespace MycroForge.PluginTemplate; -public class HelloWorldCommand : Command, ISubCommandOf +public class ExampleCommand : Command, ISubCommandOf { private readonly Argument NameArgument = new(name: "name", description: "The name of the person to greet"); @@ -15,8 +15,8 @@ public class HelloWorldCommand : Command, ISubCommandOf 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 { 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!" ); } } \ No newline at end of file diff --git a/MycroForge.PluginTemplate/HelloWorldCommandPlugin.cs b/MycroForge.PluginTemplate/ExampleCommandPlugin.cs similarity index 67% rename from MycroForge.PluginTemplate/HelloWorldCommandPlugin.cs rename to MycroForge.PluginTemplate/ExampleCommandPlugin.cs index 7982dd1..2bbf35f 100644 --- a/MycroForge.PluginTemplate/HelloWorldCommandPlugin.cs +++ b/MycroForge.PluginTemplate/ExampleCommandPlugin.cs @@ -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, HelloWorldCommand>(); + services.AddScoped, ExampleCommand>(); } } \ No newline at end of file