Clean up some lingering gajumaru refs

This commit is contained in:
Ulf Wiger 2025-02-25 12:41:56 +01:00
parent b40b7ddef4
commit eb308e3acd

View File

@ -60,8 +60,9 @@
-include_lib("kernel/include/logger.hrl"). -include_lib("kernel/include/logger.hrl").
-type gmconfig() :: #{ os_env_prefix => string() -type gmconfig() :: #{ os_env_prefix => string()
, config_file_basename => string , config_file_basename => string() | 'undefined'
, config_file_search_path => [string()] , config_file_os_env => string() | 'undefined'
, config_file_search_path => [string() | fun(() -> string())]
, system_suffix => string() , system_suffix => string()
, schema => string() | map() | fun(() -> map())}. , schema => string() | map() | fun(() -> map())}.
@ -124,10 +125,30 @@ gmconfig_env(Key) ->
gmconfig_env(Key, Default) -> gmconfig_env(Key, Default) ->
maps:get(Key, gmconfig_env(), Default). maps:get(Key, gmconfig_env(), Default).
search_path() -> search_path(config_file).
search_path(Kind) ->
Key = case Kind of
config_file -> config_file_search_path;
system_defaults -> system_defaults_search_path
end,
case gmconfig_env(Key, undefined) of
undefined -> [];
Path0 when is_list(Path0) ->
lists:map(
fun(F) when is_function(F, 0) ->
F();
(D) when is_list(D) ->
D
end, Path0)
end.
default_gmconfig() -> default_gmconfig() ->
#{ os_env_prefix => "GM" #{ os_env_prefix => "GM"
, config_file_basename => "gmconfig" , config_file_basename => "gmconfig"
, config_file_os_env => undefined
, config_file_search_path => ["."] , config_file_search_path => ["."]
, system_defaults_search_path => [fun setup:data_dir/0]
, system_suffix => "" }. , system_suffix => "" }.
%% This function is similar to application:get_env/2, except %% This function is similar to application:get_env/2, except
@ -606,22 +627,25 @@ command_line_config_file() ->
end. end.
default_config_file() -> default_config_file() ->
case os:getenv("GAJUMARU_CONFIG") of case gmconfig_env(config_file_os_env, undefined) of
false -> undefined ->
case setup:get_env(aecore, config) of search_default_config();
{ok, F} -> F; E ->
_ -> search_default_config() case os:getenv(E) of
end; false -> search_default_config();
F -> F -> F
F end
end. end.
search_default_config() -> search_default_config() ->
Dirs = [filename:join([os:getenv("HOME"), ".gajumaru", "gajumaru"]), case gmconfig_env(config_file_basename, undefined) of
setup:home()], undefined -> undefined;
SystemSuffix = get_system_suffix(), Basename ->
Fname = "gajumaru" ++ SystemSuffix ++ ".{json,yaml}", Dirs = search_path(),
search_for_config_file(Dirs, Fname). SystemSuffix = get_system_suffix(),
Fname = Basename ++ SystemSuffix ++ ".{json,yaml}",
search_for_config_file(Dirs, Fname)
end.
search_for_config_file(Dirs, FileWildcard) -> search_for_config_file(Dirs, FileWildcard) ->
lists:foldl( lists:foldl(
@ -1006,14 +1030,20 @@ load_system_defaults() ->
load_system_defaults(report). load_system_defaults(report).
load_system_defaults(Mode) -> load_system_defaults(Mode) ->
SystemSuffix = get_system_suffix(), case gmconfig_env(config_file_basename, undefined) of
Fname = "gajumaru_defaults" ++ SystemSuffix ++ ".{yaml,json}",
case search_for_config_file([setup:data_dir()], Fname) of
undefined -> undefined ->
ok; ok;
ConfigFile -> Basename ->
?LOG_DEBUG("Loading system defaults from ~s", [ConfigFile]), SystemSuffix = get_system_suffix(),
load_config_file(ConfigFile, Mode) Fname = Basename ++ "_defaults" ++ SystemSuffix ++ ".{yaml,json}",
Path = search_path(system_defaults),
case search_for_config_file(Path, Fname) of
undefined ->
ok;
ConfigFile ->
?LOG_DEBUG("Loading system defaults from ~s", [ConfigFile]),
load_config_file(ConfigFile, Mode)
end
end. end.
get_system_suffix() -> get_system_suffix() ->