From ed6db6298d17567f44cee0d9fd4b451f58122ab4 Mon Sep 17 00:00:00 2001 From: Andrew Lalis Date: Fri, 24 Mar 2023 09:01:10 +0100 Subject: [PATCH] Added start of infra to runner.d --- runner.d | 53 +++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 49 insertions(+), 4 deletions(-) mode change 100644 => 100755 runner.d diff --git a/runner.d b/runner.d old mode 100644 new mode 100755 index e7e60a8..81fd820 --- a/runner.d +++ b/runner.d @@ -11,12 +11,57 @@ import std.process; import std.stdio; import std.string; import std.uni; +import core.thread; + +int main() { + bool running = true; + writeln("Gymboard CLI: Type \"help\" for more information. Type \"exit\" to exit the CLI."); + while (running) { + string[] commandAndArgs = readln().strip.split!isWhite; + if (commandAndArgs.length == 0) continue; + string command = commandAndArgs[0].toLower(); + if (command == "help") { + showHelp(); + } else if (command == "exit") { + running = false; + } else if (command in commands) { + commands[command](commandAndArgs.length > 1 ? commandAndArgs[1 .. $] : []); + } else { + writefln!"Unknown command \"%s\"."(command); + } + } + writeln("Goodbye!"); + return 0; +} alias CommandFunction = void function(string[] args); -int main() { - while (true) { - string[] command = readln().split!isWhite; +CommandFunction[string] commands; + +void registerCommand(string name, CommandFunction func) { + commands[name] = func; +} + +void showHelp() { + writeln(q"HELP +Gymboard CLI: A tool for streamlining development. + +Commands: + +help Shows this message. +exit Exits the CLI, stopping any running services. +HELP"); +} + +class ProcessRunner : Thread { + private Pid processId; + + public this(ProcessPipes pipes) { + super(&this.run); + this.processId = pipes.pid(); + } + + private void run() { } -} \ No newline at end of file +}