Clean up some lingering gajumaru refs
This commit is contained in:
parent
b40b7ddef4
commit
eb308e3acd
@ -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;
|
||||||
|
Basename ->
|
||||||
|
Dirs = search_path(),
|
||||||
SystemSuffix = get_system_suffix(),
|
SystemSuffix = get_system_suffix(),
|
||||||
Fname = "gajumaru" ++ SystemSuffix ++ ".{json,yaml}",
|
Fname = Basename ++ SystemSuffix ++ ".{json,yaml}",
|
||||||
search_for_config_file(Dirs, Fname).
|
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) ->
|
||||||
|
case gmconfig_env(config_file_basename, undefined) of
|
||||||
|
undefined ->
|
||||||
|
ok;
|
||||||
|
Basename ->
|
||||||
SystemSuffix = get_system_suffix(),
|
SystemSuffix = get_system_suffix(),
|
||||||
Fname = "gajumaru_defaults" ++ SystemSuffix ++ ".{yaml,json}",
|
Fname = Basename ++ "_defaults" ++ SystemSuffix ++ ".{yaml,json}",
|
||||||
case search_for_config_file([setup:data_dir()], Fname) of
|
Path = search_path(system_defaults),
|
||||||
|
case search_for_config_file(Path, Fname) of
|
||||||
undefined ->
|
undefined ->
|
||||||
ok;
|
ok;
|
||||||
ConfigFile ->
|
ConfigFile ->
|
||||||
?LOG_DEBUG("Loading system defaults from ~s", [ConfigFile]),
|
?LOG_DEBUG("Loading system defaults from ~s", [ConfigFile]),
|
||||||
load_config_file(ConfigFile, Mode)
|
load_config_file(ConfigFile, Mode)
|
||||||
|
end
|
||||||
end.
|
end.
|
||||||
|
|
||||||
get_system_suffix() ->
|
get_system_suffix() ->
|
||||||
|
Loading…
x
Reference in New Issue
Block a user