using System.CommandLine; using MycroForge.Core; using MycroForge.Core.Contract; using RootCommand = MycroForge.Core.RootCommand; namespace MycroForge.PluginTemplate; public class ExampleCommand : 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 ExampleCommand(ProjectContext context) : base("example", "A basic command plugin generated by the 'm4g plugin init' command") { _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("example.txt", $"Hello {name}!", "This file was generated by the 'm4g example' command!" ); } }