added method to write config
This commit is contained in:
@@ -9,7 +9,7 @@ module Kotatsu
|
|||||||
CONFIG_DIR = Path.new(Path.home, ".config", "kotatsu")
|
CONFIG_DIR = Path.new(Path.home, ".config", "kotatsu")
|
||||||
CONFIG_FILE = Path.new(CONFIG_DIR, "config.json")
|
CONFIG_FILE = Path.new(CONFIG_DIR, "config.json")
|
||||||
|
|
||||||
def self.buildConfigDefault()
|
def self.buildConfig() #to be deprecated
|
||||||
conf = JSON.build do |json|
|
conf = JSON.build do |json|
|
||||||
json.object do
|
json.object do
|
||||||
json.field "config_version", 1
|
json.field "config_version", 1
|
||||||
@@ -34,6 +34,30 @@ module Kotatsu
|
|||||||
return conf
|
return conf
|
||||||
end
|
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()
|
def self.readConfig()
|
||||||
conf = JSON.parse(File.read(CONFIG_FILE))
|
conf = JSON.parse(File.read(CONFIG_FILE))
|
||||||
version = conf["config_version"].as_i
|
version = conf["config_version"].as_i
|
||||||
@@ -53,7 +77,7 @@ module Kotatsu
|
|||||||
exit(1)
|
exit(1)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
File.write(file, buildConfigDefault())
|
File.write(file, buildConfig())
|
||||||
if File.exists?(file) == false
|
if File.exists?(file) == false
|
||||||
STDERR.puts "ERROR! Could not create file: #{file}"
|
STDERR.puts "ERROR! Could not create file: #{file}"
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|||||||
Reference in New Issue
Block a user