added config file creation
This commit is contained in:
@@ -5,6 +5,23 @@ require "http/server"
|
|||||||
|
|
||||||
module Kotatsu
|
module Kotatsu
|
||||||
VERSION = "0.1.0"
|
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|
|
OptionParser.parse do |parser|
|
||||||
parser.banner = "Kotatsu - Easy to configure server start page"
|
parser.banner = "Kotatsu - Easy to configure server start page"
|
||||||
@@ -26,6 +43,11 @@ module Kotatsu
|
|||||||
end
|
end
|
||||||
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|
|
webserv = HTTP::Server.new do |context|
|
||||||
context.response.content_type = "text/plain"
|
context.response.content_type = "text/plain"
|
||||||
context.response.print "Running kotatsu #{VERSION}"
|
context.response.print "Running kotatsu #{VERSION}"
|
||||||
|
|||||||
Reference in New Issue
Block a user