From 9b284ee2ced88cc843fa9254c6c41d07f6c2180a Mon Sep 17 00:00:00 2001 From: Jon Michael Aanes Date: Tue, 9 Jan 2018 13:29:15 +0100 Subject: [PATCH] Implemented lazy load of platform specific functionallity, and a different test for that functionallity. --- suggest-require.lua | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/suggest-require.lua b/suggest-require.lua index 98de5bd..e170d70 100644 --- a/suggest-require.lua +++ b/suggest-require.lua @@ -56,24 +56,32 @@ local function package_config () } end -local iterate_files_in_subfiles +local iterate_files_in_subfiles = function (...) + -- This outer function is a wrapper, that lazily loads the correct + -- version of the iterate function, based on the availability of + -- the commands. -if package_config().dir_sep == '/' then - function iterate_files_in_subfiles (root_path) - -- On unix - -- Use `find` to find files in folders below the given matching. + if os.execute 'find -false' == 0 then + iterate_files_in_subfiles = function (root_path) + -- On unix + -- Use `find` to find files in folders below the given matching. - assert(type(root_path) == 'string') - local start_directory = root_path:match '^(.-)?' or root_path - local pfile = io.popen ('find -L "'..start_directory..'" -type f ! -path \'*/\\.*\' -print0 2> /dev/null') - local list_str = pfile:read '*all' - pfile:close() + assert(type(root_path) == 'string') + local start_directory = root_path:match '^(.-)?' or root_path + local pfile = io.popen ('find -L "'..start_directory..'" -type f ! -path \'*/\\.*\' -print0 2> /dev/null') + local list_str = pfile:read '*all' + pfile:close() - return list_str:gmatch '[^%z]+' + return list_str:gmatch '[^%z]+' + end + else + -- Other platforms + error '[suggest-require]: Your platform does not possess the "find" utility, and is thus not currently supported.' end -else - -- On windows - error '[suggest-require]: Windows is not currently supported.' + + ----- + + return iterate_files_in_subfiles(...) end -------------------------------------------------------------------------------- @@ -199,7 +207,7 @@ local function get_available_module_names () for name in pairs(dedub) do module_names[#module_names+1] = name end table.sort(module_names) - -- Output assertions + -- Assert that output is correctly formatted assert(type(module_names) == 'table') for i = 1, #module_names do assert(type(module_names[i]) == 'string')