Compare commits
4 Commits
0e38090ae9
...
4fc6ac892f
| Author | SHA1 | Date | |
|---|---|---|---|
| 4fc6ac892f | |||
| c730a2213c | |||
| e67c755d37 | |||
| 8dacf6cd15 |
@@ -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.buildConfig()
|
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,47 @@ 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()
|
||||||
|
conf = JSON.parse(File.read(CONFIG_FILE))
|
||||||
|
version = conf["config_version"].as_i
|
||||||
|
port = conf["port"].as_i
|
||||||
|
title = conf["title"].as_s
|
||||||
|
|
||||||
|
t_services = conf["services"].as_a
|
||||||
|
services = [] of Array(String)
|
||||||
|
i = 0
|
||||||
|
while t_services.size > i
|
||||||
|
services << [conf["services"][i][0].as_s, conf["services"][i][1].as_s, conf["services"][i][2].as_s]
|
||||||
|
i+=1
|
||||||
|
end
|
||||||
|
|
||||||
|
return version, port, title, services
|
||||||
|
end
|
||||||
|
|
||||||
def self.makeConfig(file, dir)
|
def self.makeConfig(file, dir)
|
||||||
puts "Creating new config file in #{file}"
|
puts "Creating new config file in #{file}"
|
||||||
if Dir.exists?(dir) == false
|
if Dir.exists?(dir) == false
|
||||||
@@ -73,10 +114,36 @@ module Kotatsu
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
parser.on "add", "Add a service" do
|
||||||
|
if File.exists?(CONFIG_FILE) == true
|
||||||
|
version, port, title, services = readConfig()
|
||||||
|
print "Name: "
|
||||||
|
s_name = gets.to_s
|
||||||
|
print "Link: "
|
||||||
|
s_link = gets.to_s
|
||||||
|
print "Icon: "
|
||||||
|
s_icon = gets.to_s
|
||||||
|
s_service = [s_name, s_link, s_icon]
|
||||||
|
|
||||||
|
services_new = [] of Array(String)
|
||||||
|
i = 0
|
||||||
|
while services.size > i
|
||||||
|
services_new << services[i]
|
||||||
|
i+=1
|
||||||
|
end
|
||||||
|
services_new << s_service
|
||||||
|
|
||||||
|
writeConfig(version, port, title, services_new)
|
||||||
|
exit
|
||||||
|
else
|
||||||
|
STDERR.puts "ERROR! Config file not found: #{CONFIG_FILE}"
|
||||||
|
exit(1)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
parser.on "list", "Lists all services" do
|
parser.on "list", "Lists all services" do
|
||||||
if File.exists?(CONFIG_FILE) == true
|
if File.exists?(CONFIG_FILE) == true
|
||||||
conf = JSON.parse(File.read(CONFIG_FILE))
|
_, _, _, services = readConfig()
|
||||||
services = conf["services"].as_a
|
|
||||||
i = 0
|
i = 0
|
||||||
while services.size > i
|
while services.size > i
|
||||||
puts "##{i}: #{services[i][0]} ; #{services[i][1]} ; #{services[i][2]}"
|
puts "##{i}: #{services[i][0]} ; #{services[i][1]} ; #{services[i][2]}"
|
||||||
|
|||||||
Reference in New Issue
Block a user