Configuration parameter replaced by --project.

master
Karchnu 2020-12-13 02:03:04 +01:00
parent 75924a3412
commit 9010a55eb6
1 changed files with 16 additions and 8 deletions

View File

@ -7,16 +7,22 @@ class Baguette::Context
end
class Baguette::Configuration
class_property project_directory : String? = nil
class Base
include YAML::Serializable
# Check for provided file first,
# then $XDG_CONFIG_HOME/<class>.yml,
# then /etc/baguette/<class>.yml.
# Check for $XDG_CONFIG_HOME/baguette/<project-name>/<class>.yml,
# then /etc/baguette/<project-name>/<class>.yml.
# (project name is not mandatory)
def self.get(file : String? = nil)
filename = "/" + (self.name.downcase.gsub /baguette::configuration::/, "") + ".yml"
directory = "/baguette"
if pdir = Baguette::Configuration.project_directory
directory += "/" + pdir
end
suffix = "#{directory}#{filename}"
user_configuration = (ENV["XDG_CONFIG_HOME"]? || "~/.config") + suffix
system_configuration = "/etc#{suffix}"
@ -36,6 +42,8 @@ class Baguette::Configuration
self.from_yaml File.read(system_configuration)
else
Baguette::Log.warning "No configuration found"
Baguette::Log.warning "Searched in: #{user_configuration}"
Baguette::Log.warning "Searched in: #{system_configuration}"
nil
end
end
@ -63,7 +71,7 @@ class Baguette::Configuration
# Read options from the CLI.
# We currently want to know:
# - the program verbosity
# - the configuration file to use
# - the configuration directory to use (project name)
# - if the configuration files should be ignored
# - if this is just a simulation (used to print configuration then quit)
def self.option_parser
@ -74,7 +82,7 @@ class Baguette::Configuration
help = false
OptionParser.parse do |parser|
parser.banner = "usage: #{PROGRAM_NAME} [-ns][-c configuration-file]"
parser.banner = "usage: #{PROGRAM_NAME} [-ns][--project project-name]"
parser.on "-s", "--simulation",
"Print configuration then quit." do
@ -91,9 +99,9 @@ class Baguette::Configuration
Baguette::Context.verbosity = v.to_i
end
parser.on "-c file", "--configuration file",
"Configuration file." do |file|
configuration_file = file
parser.on "--project project-name",
"Project name. Will search in $XDG_CONFIG_HOME/baguette/<project-name>/<class>.yml then /etc/baguette/<project-name>/<class>.yml." do |dir|
Baguette::Configuration.project_directory = dir
end
parser.invalid_option do |arg|