added config file creation

This commit is contained in:
2021-12-29 04:23:57 +01:00
parent dbf7c0a6a6
commit 74d38ff6eb

View File

@@ -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}"