diff --git a/src/kotatsu.cr b/src/kotatsu.cr index e76559c..0834cb5 100644 --- a/src/kotatsu.cr +++ b/src/kotatsu.cr @@ -9,7 +9,7 @@ module Kotatsu CONFIG_DIR = Path.new(Path.home, ".config", "kotatsu") CONFIG_FILE = Path.new(CONFIG_DIR, "config.json") - def self.buildConfigDefault() + def self.buildConfig() #to be deprecated conf = JSON.build do |json| json.object do json.field "config_version", 1 @@ -34,6 +34,30 @@ module Kotatsu return conf end + def self.writeConfig(version, port, title, services) + i = 0 + conf = JSON.build do |json| + json.object do + json.field "config_version", version + json.field "port", port + json.field "title", title + json.field "services" do + json.array do + while services.size > i + json.array do + json.string services[i][0] + json.string services[i][1] + json.string services[i][2] + end + i+=1 + end + end + end + end + end + File.write(CONFIG_FILE, conf) + end + def self.readConfig() conf = JSON.parse(File.read(CONFIG_FILE)) version = conf["config_version"].as_i @@ -53,7 +77,7 @@ module Kotatsu exit(1) end end - File.write(file, buildConfigDefault()) + File.write(file, buildConfig()) if File.exists?(file) == false STDERR.puts "ERROR! Could not create file: #{file}" exit(1)