From 74d38ff6eb202bac442350bda64eaf8fbc105e1c Mon Sep 17 00:00:00 2001 From: luneko Date: Wed, 29 Dec 2021 04:23:57 +0100 Subject: [PATCH] added config file creation --- src/kotatsu.cr | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/kotatsu.cr b/src/kotatsu.cr index 0ea1057..fec3d8f 100644 --- a/src/kotatsu.cr +++ b/src/kotatsu.cr @@ -5,6 +5,23 @@ require "http/server" module Kotatsu VERSION = "0.1.0" + CONFIG_DIR = Path.new(Path.home, ".config", "kotatsu") + CONFIG_FILE = Path.new(CONFIG_DIR, "config.json") + + def self.makeConfig(file, dir) + puts "Creating new config file in #{file}" + if Dir.exists?(dir) == false + Dir.mkdir(dir) + if Dir.exists?(dir) == false + STDERR.puts "ERROR! Could not create directory: #{dir}" + end + end + File.write(file, VERSION) + if File.exists?(file) == false + STDERR.puts "ERROR! Could not create file: #{file}" + exit(1) + end + end OptionParser.parse do |parser| parser.banner = "Kotatsu - Easy to configure server start page" @@ -26,6 +43,11 @@ module Kotatsu end end + if File.exists?(CONFIG_FILE) == false + puts "Could not find config file" + makeConfig(CONFIG_FILE, CONFIG_DIR) + end + webserv = HTTP::Server.new do |context| context.response.content_type = "text/plain" context.response.print "Running kotatsu #{VERSION}"