From 46e7c7156b0819c26682d886054d446a6841818e Mon Sep 17 00:00:00 2001 From: "Robin H. Johnson" Date: Sun, 24 Dec 2023 23:01:32 -0800 Subject: [PATCH] fix(subcommand): clarify config load behavior (no logic change) Signed-off-by: Robin H. Johnson Resolves: https://github.com/voxpupuli/hiera-eyaml/pull/360#discussion_r1435966277 --- lib/hiera/backend/eyaml/subcommand.rb | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/lib/hiera/backend/eyaml/subcommand.rb b/lib/hiera/backend/eyaml/subcommand.rb index 9f1815c..bbda6b2 100644 --- a/lib/hiera/backend/eyaml/subcommand.rb +++ b/lib/hiera/backend/eyaml/subcommand.rb @@ -33,12 +33,20 @@ class << self def self.load_config_file config = { options: {}, sources: [] } - config_paths = [ - '/etc/eyaml/config.yaml', - "#{ENV.fetch('HOME', nil)}/.eyaml/config.yaml", - '.eyaml/config.yaml', - "#{ENV.fetch('EYAML_CONFIG', nil)}", - ] + + config_paths = [] + # Global + config_paths += ['/etc/eyaml/config.yaml'] + # Home directory + env_home = ENV.fetch('HOME', nil) + config_paths += [ "#{env_home}/.eyaml/config.yaml" ] if env_home + # Relative to current directory + config_paths += [ ".eyaml/config.yaml" ] + # Explicit ENV variable. + env_eyaml_config = ENV.fetch('EYAML_CONFIG', nil) + config_paths += [env_eyaml_config] if env_eyaml_config + + # Load each path and stack configs. config_paths.each do |config_file| next unless config_file and File.file? config_file