# MystBin ! - Builtins.cs using CommandLine; namespace Builtins { // Echo command class EchoCommand : Command { public EchoCommand() : base("echo", docstring: """ A simple echo command that repeats back whatever the user sends. If the first argument is a number, it will be treated as the number of times to repeat the following sequence of characters, joined by a space. Usage ----- >>> echo hello world hello world >>> echo 3 hi hi hi hi """ ) { } public override void Callback() { string echoString = ReturnedArguments[0]; string[] echoStringParts = echoString.Split(' '); if (echoStringParts.Length == 1) { Console.WriteLine(echoString); return; } string firstEchoWord = echoStringParts[0]; string restOfEchoWord = string.Join(" ", echoStringParts[1 .. echoStringParts.Length]); if (int.TryParse(firstEchoWord, out int count)) { Console.WriteLine(string.Join(" ", Enumerable.Range(0, count + 1).Select(_ => restOfEchoWord))); } else { Console.WriteLine(echoString); } } } // Close command class CloseCommand : Command { public CloseCommand() : base("close", docstring: """ A simple close command that stops the process entirely and closes the window. Usage ----- >>> close """) { } public override void Callback() { Environment.Exit(0); } } // Help command class HelpCommand : Command { public HelpCommand() : base("help") { } public override void Callback() { // Get what the user queried with the help command string query = ReturnedArguments[0]; // Get all the commands subclassing command List search = CreatedCommands.Where(cmd => cmd.Name == query).ToList(); if (search.Count == 0) { Console.WriteLine($"The search for command '{query}' yielded no results."); return; } Command command = search[0]; string title = $"Help on command '{command}':"; Console.WriteLine($"{title}\n{new string('-', title.Length)}\n{command.Docstring}\n{new string('-', title.Length)}"); } } }