aboutsummaryrefslogtreecommitdiffstats
path: root/src/rlx_util.erl
diff options
context:
space:
mode:
authorJosé Valim <[email protected]>2013-11-18 10:28:39 +0100
committerJosé Valim <[email protected]>2013-11-18 10:42:15 +0100
commit73b24fd1a0604e413fece30181cc632c1081aa29 (patch)
tree06371825a8876bc8d19e10755241510b341bbb02 /src/rlx_util.erl
parent10620765c5028c24d57caba20b8e86b98351e3a5 (diff)
downloadrelx-73b24fd1a0604e413fece30181cc632c1081aa29.tar.gz
relx-73b24fd1a0604e413fece30181cc632c1081aa29.tar.bz2
relx-73b24fd1a0604e413fece30181cc632c1081aa29.zip
Support wildcards in lib dirs
Wildcards are supported in both lib_dirs in config files as well via the -l command line option.
Diffstat (limited to 'src/rlx_util.erl')
-rw-r--r--src/rlx_util.erl20
1 files changed, 19 insertions, 1 deletions
diff --git a/src/rlx_util.erl b/src/rlx_util.erl
index 53e9122..48e2ee1 100644
--- a/src/rlx_util.erl
+++ b/src/rlx_util.erl
@@ -28,7 +28,8 @@
is_error/1,
error_reason/1,
indent/1,
- optional_to_string/1]).
+ optional_to_string/1,
+ wildcard_paths/1]).
-define(ONE_LEVEL_INDENT, " ").
%%============================================================================
@@ -96,6 +97,23 @@ optional_to_string(undefined) ->
optional_to_string(Value) when is_list(Value) ->
Value.
+%% @doc expand wildcards and names in the given paths
+-spec wildcard_paths([file:filename_all()]) -> [string()].
+wildcard_paths(Paths) ->
+ [filename:absname(Expanded) || Path <- Paths, Expanded <- wildcard(Path)].
+
+%% In case the given directory does not expand,
+%% we return it back in a list so we trigger the
+%% proper error reportings.
+-spec wildcard(file:filename_all()) -> [string()].
+wildcard(Path) when is_binary(Path) ->
+ wildcard(binary_to_list(Path));
+wildcard(Path) when is_list(Path) ->
+ case filelib:wildcard(Path) of
+ [] -> [Path];
+ Paths -> Paths
+ end.
+
%%%===================================================================
%%% Test Functions
%%%===================================================================