From 5204274a76b1d4c58b37edaa009ecbfb86d12096 Mon Sep 17 00:00:00 2001 From: "Tristan B. Kildaire" Date: Thu, 30 Apr 2020 19:18:00 +0200 Subject: [PATCH] Configuration file is now read in from arguments. --- source/app.d | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/source/app.d b/source/app.d index c4ddf46..1f4456f 100644 --- a/source/app.d +++ b/source/app.d @@ -8,6 +8,7 @@ import std.stdio : File, writeln; import std.json : parseJSON, JSONValue; import listeners.listener; import listeners.types; +import std.file : exists; unittest d { @@ -15,15 +16,26 @@ unittest d main(); } -void main() +void main(string[] args) { + /* Make sure we have atleast two arguments */ + if(args.length >= 2) + { + /* Get the second argument for configuration file path */ + string configFilePath = args[1]; - /* TODO: Change this */ - string address = "0.0.0.0"; - ushort port = 2222; + /* Start thhe server if the file exists, else show an error */ + if(exists(configFilePath)) + { + startServer(args[1]); + } + else + { + writeln("Provided server configuration file \"" ~ configFilePath ~ "\" does not exist"); + } + } /* TODO: Add usage check and arguments before this */ - startServer("server.conf"); dprint("Main finished, remaining threads are keeping this open if it hangs"); }