mirror of
https://github.com/hkalexling/Mango.git
synced 2026-03-20 00:00:48 -04:00
- initial commit
This commit is contained in:
37
src/config.cr
Normal file
37
src/config.cr
Normal file
@@ -0,0 +1,37 @@
|
||||
require "yaml"
|
||||
require "uuid"
|
||||
require "base64"
|
||||
|
||||
class Config
|
||||
include YAML::Serializable
|
||||
|
||||
@[YAML::Field(key: "port")]
|
||||
property port = 9000
|
||||
|
||||
@[YAML::Field(key: "library_path")]
|
||||
property library_path = File.expand_path "~/mango-library", home: true
|
||||
|
||||
@[YAML::Field(key: "db_path")]
|
||||
property db_path = File.expand_path "~/mango-library/mango.db", home: true
|
||||
|
||||
def self.load
|
||||
cfg_path = File.expand_path "~/.config/mango/config.yml", home: true
|
||||
if File.exists? cfg_path
|
||||
return self.from_yaml File.read cfg_path
|
||||
end
|
||||
puts "The config file #{cfg_path} does not exist." \
|
||||
"Do you want mango to dump the default config there? [Y/n]"
|
||||
input = gets
|
||||
if !input.nil? && input.downcase == "n"
|
||||
abort "Aborting..."
|
||||
end
|
||||
default = self.allocate
|
||||
cfg_dir = File.dirname cfg_path
|
||||
unless Dir.exists? cfg_dir
|
||||
Dir.mkdir_p cfg_dir
|
||||
end
|
||||
File.write cfg_path, default.to_yaml
|
||||
puts "The config file has been created at #{cfg_path}."
|
||||
default
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user