using System.CommandLine; using MycroForge.Core; using MycroForge.Core.Contract; using RootCommand = MycroForge.Core.RootCommand; namespace MycroForge.PluginTemplate; public class HelloWorldCommand : Command, ISubCommandOf { private readonly Argument NameArgument = new(name: "name", description: "The name of the person to greet"); private readonly Option AllCapsOption = new(aliases: ["-a", "--all-caps"], description: "Print the name in all caps"); private readonly ProjectContext _context; public HelloWorldCommand(ProjectContext context) : base("hello", "An example command generated by dotnet new using the m4gp template") { _context = context; AddArgument(NameArgument); AddOption(AllCapsOption); this.SetHandler(ExecuteAsync, NameArgument, AllCapsOption); } private async Task ExecuteAsync(string name, bool allCaps) { name = allCaps ? name.ToUpper() : name; await _context.CreateFile("hello_world.txt", $"Hello {name}!", "This file was generated by your custom command!" ); } }