process plain args, update zompify.sh
This commit is contained in:
parent
d0a0d039c0
commit
4ee669ebba
@ -31,6 +31,7 @@
|
|||||||
-export([search_for_config_file/2]).
|
-export([search_for_config_file/2]).
|
||||||
-export([apply_os_env/0,
|
-export([apply_os_env/0,
|
||||||
apply_os_env/3]).
|
apply_os_env/3]).
|
||||||
|
-export([process_plain_args/0]).
|
||||||
-export([data_dir/1]).
|
-export([data_dir/1]).
|
||||||
-export([check_config/1]).
|
-export([check_config/1]).
|
||||||
|
|
||||||
@ -74,6 +75,7 @@
|
|||||||
, config_file_basename => string() | 'undefined'
|
, config_file_basename => string() | 'undefined'
|
||||||
, config_file_os_env => string() | 'undefined'
|
, config_file_os_env => string() | 'undefined'
|
||||||
, config_file_search_path => [string() | fun(() -> string())]
|
, config_file_search_path => [string() | fun(() -> string())]
|
||||||
|
, config_plain_args => string() | 'undefined'
|
||||||
, system_suffix => string()
|
, system_suffix => string()
|
||||||
, config_formats => #{ extension() => decoder_fun() }
|
, config_formats => #{ extension() => decoder_fun() }
|
||||||
, schema => string() | map() | fun(() -> map())}.
|
, schema => string() | map() | fun(() -> map())}.
|
||||||
@ -159,6 +161,7 @@ default_gmconfig_env() ->
|
|||||||
, config_file_search_path => ["."]
|
, config_file_search_path => ["."]
|
||||||
, config_formats => #{ "json" => fun json_decode/1
|
, config_formats => #{ "json" => fun json_decode/1
|
||||||
, "eterm" => fun eterm_consult/1 }
|
, "eterm" => fun eterm_consult/1 }
|
||||||
|
, config_plain_args => undefined
|
||||||
, system_defaults_search_path => [fun setup:data_dir/0]
|
, system_defaults_search_path => [fun setup:data_dir/0]
|
||||||
, system_suffix => "" }.
|
, system_suffix => "" }.
|
||||||
|
|
||||||
@ -508,7 +511,6 @@ load_config_file(File, Mode) when Mode =:= check;
|
|||||||
do_load_user_config(File, store, Mode).
|
do_load_user_config(File, store, Mode).
|
||||||
|
|
||||||
apply_os_env() ->
|
apply_os_env() ->
|
||||||
ok = application:ensure_started(gproc),
|
|
||||||
Pfx = os_env_prefix(),
|
Pfx = os_env_prefix(),
|
||||||
ConfigMap = pt_get_config(),
|
ConfigMap = pt_get_config(),
|
||||||
case apply_os_env(Pfx, schema(), ConfigMap) of
|
case apply_os_env(Pfx, schema(), ConfigMap) of
|
||||||
@ -548,6 +550,35 @@ apply_os_env(Pfx, Schema, ConfigMap) ->
|
|||||||
error(E)
|
error(E)
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
process_plain_args() ->
|
||||||
|
case gmconfig_env(config_plain_args, undefined) of
|
||||||
|
undefined ->
|
||||||
|
ok;
|
||||||
|
Str ->
|
||||||
|
PlainArgs = init:get_plain_arguments(),
|
||||||
|
Schema = schema(),
|
||||||
|
Map = process_plain_args_(PlainArgs, Str, schema(), #{}),
|
||||||
|
?LOG_INFO("Map from plain args: ~p", [Map]),
|
||||||
|
if map_size(Map) > 0 ->
|
||||||
|
update_config_(Map, pt_get_config(), Schema, report);
|
||||||
|
true ->
|
||||||
|
no_change
|
||||||
|
end
|
||||||
|
end.
|
||||||
|
|
||||||
|
process_plain_args_([Tag, K, V | Rest], Tag, Schema, Map) ->
|
||||||
|
Path = plain_path_arg(K),
|
||||||
|
Value = coerce_type(Path, V, Schema),
|
||||||
|
Map1 = update_map(to_map(Path, Value), Map),
|
||||||
|
process_plain_args_(Rest, Tag, Schema, Map1);
|
||||||
|
process_plain_args_([_ | T], Tag, Schema, Map) ->
|
||||||
|
process_plain_args_(T, Tag, Schema, Map);
|
||||||
|
process_plain_args_([], _, _, Map) ->
|
||||||
|
Map.
|
||||||
|
|
||||||
|
plain_path_arg(Str) ->
|
||||||
|
re:split(Str, <<"__">>, [{return, binary}]).
|
||||||
|
|
||||||
to_map(K, V) ->
|
to_map(K, V) ->
|
||||||
to_map(K, V, #{}).
|
to_map(K, V, #{}).
|
||||||
|
|
||||||
|
@ -2,10 +2,10 @@
|
|||||||
{type,app}.
|
{type,app}.
|
||||||
{modules,[]}.
|
{modules,[]}.
|
||||||
{prefix,"gmconfig"}.
|
{prefix,"gmconfig"}.
|
||||||
{desc,"Configuration management support"}.
|
|
||||||
{author,"Ulf Wiger"}.
|
{author,"Ulf Wiger"}.
|
||||||
{package_id,{"uwiger","gmconfig",{0,1,0}}}.
|
{desc,"Configuration management support"}.
|
||||||
{deps,[{"uwiger","setup",{2,2,3}}]}.
|
{package_id,{"uwiger","gmconfig",{0,1,2}}}.
|
||||||
|
{deps,[{"uwiger","setup",{2,2,4}}]}.
|
||||||
{key_name,none}.
|
{key_name,none}.
|
||||||
{a_email,"ulf@wiger.net"}.
|
{a_email,"ulf@wiger.net"}.
|
||||||
{c_email,"ulf@wiger.net"}.
|
{c_email,"ulf@wiger.net"}.
|
||||||
|
38
zompify.sh
38
zompify.sh
@ -2,11 +2,41 @@
|
|||||||
set -e
|
set -e
|
||||||
|
|
||||||
APP=$(basename "$PWD")
|
APP=$(basename "$PWD")
|
||||||
|
|
||||||
SRC="_build/default/lib/$APP"
|
SRC="_build/default/lib/$APP"
|
||||||
DST="$PWD/_build/zomp/lib/$APP"
|
DST="$PWD/_build/zomp/lib/$APP"
|
||||||
|
IGNORE_FILE="zomp.ignore"
|
||||||
|
|
||||||
mkdir -p "$DST"
|
mkdir -p "$DST"
|
||||||
find "$SRC" -type l ! -exec test -e {} \; -delete
|
|
||||||
cp -aR -L "$SRC/." "$DST/"
|
# Remove broken symlinks
|
||||||
|
find "$SRC" -type l ! -exec test -e {} \; -delete || true
|
||||||
|
|
||||||
|
# Build ignore matcher
|
||||||
|
IGNORE_TEMP=$(mktemp)
|
||||||
|
trap "rm -f $IGNORE_TEMP" EXIT
|
||||||
|
|
||||||
|
# Expand globs in zomp.ignore to patterns suitable for grep
|
||||||
|
if [ -e "$IGNORE_FILE" ]; then
|
||||||
|
grep -v '^\s*#' "$IGNORE_FILE" | sed 's#/#\\/#g' | sed 's/\./\\./g' | sed 's/\*/.*/g' > "$IGNORE_TEMP"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Copy Git-tracked and Zomp-allowed files
|
||||||
|
git ls-files -z | while IFS= read -r -d '' file; do
|
||||||
|
# Skip if ignored
|
||||||
|
echo "$file" | grep -Eq -f "$IGNORE_TEMP" && continue
|
||||||
|
# Only copy if file exists in the build dir
|
||||||
|
if [ -e "$SRC/$file" ]; then
|
||||||
|
mkdir -p "$DST/$(dirname "$file")"
|
||||||
|
cp -a "$SRC/$file" "$DST/$file"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
rm "$IGNORE_TEMP"
|
||||||
|
|
||||||
|
# Copy metadata
|
||||||
cp "$PWD/zomp.meta" "$DST/"
|
cp "$PWD/zomp.meta" "$DST/"
|
||||||
cp "$PWD/Emakefile" "$DST"
|
cp "$PWD/Emakefile" "$DST/"
|
||||||
rm "$DST"/ebin/*.beam
|
|
||||||
|
# Clean up beam files just in case
|
||||||
|
[ -d "$DST/ebin" ] && find "$DST/ebin" -name '*.beam' -exec rm -f {} + || true
|
||||||
|
Loading…
x
Reference in New Issue
Block a user