From 73b24fd1a0604e413fece30181cc632c1081aa29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Mon, 18 Nov 2013 10:28:39 +0100 Subject: Support wildcards in lib dirs Wildcards are supported in both lib_dirs in config files as well via the -l command line option. --- src/rlx_util.erl | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'src/rlx_util.erl') 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 %%%=================================================================== -- cgit v1.2.3