Compare commits

...

2 Commits

Author SHA1 Message Date
8a7b6c9fd0 added actual json to default config 2021-12-30 15:23:51 +01:00
8bd123a030 added option to make config without running the server 2021-12-30 14:45:50 +01:00

View File

@@ -2,12 +2,38 @@
require "option_parser"
require "http/server"
require "json"
module Kotatsu
VERSION = "0.1.0"
CONFIG_DIR = Path.new(Path.home, ".config", "kotatsu")
CONFIG_FILE = Path.new(CONFIG_DIR, "config.json")
def self.buildConfig()
conf = JSON.build do |json|
json.object do
json.field "config_version", 1
json.field "port", 8080
json.field "title", "Kotatsu"
json.field "services" do
json.array do
json.array do
json.string "Peko! Peko! Peko!"
json.string "https://peko.dance/"
json.string "none"
end
json.array do
json.string "Entertainment Company"
json.string "https://hololive.dance/"
json.string "none"
end
end
end
end
end
return conf
end
def self.makeConfig(file, dir)
puts "Creating new config file in #{file}"
if Dir.exists?(dir) == false
@@ -17,7 +43,7 @@ module Kotatsu
exit(1)
end
end
File.write(file, VERSION)
File.write(file, buildConfig())
if File.exists?(file) == false
STDERR.puts "ERROR! Could not create file: #{file}"
exit(1)
@@ -37,6 +63,16 @@ module Kotatsu
exit
end
parser.on "-mc", "--make-config", "Creates config file without running kotatsu" do
if File.exists?(CONFIG_FILE) == false
makeConfig(CONFIG_FILE, CONFIG_DIR)
exit
else
puts "Config already exists"
exit
end
end
parser.invalid_option do |flag|
STDERR.puts "ERROR! Not a valid option: #{flag}"
STDERR.puts "Use -h or --help for all available options"