From 2bbc035f5dcc3ecd62724b9d1de0e7e3ea902379 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Tue, 20 Nov 2018 14:52:59 -0800 Subject: Simplifying the filesystem code (no longer entangled with nomsupath) and using that to simplify the tools. Now the tools directly take lists of file paths rather than things that might go through nomsupath or directories or get processed by filetype. Use your shell for globbing stuff like `nomsu tools/test.nom core/*.nom` --- files.lua | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'files.lua') diff --git a/files.lua b/files.lua index abc9d95..72ec63b 100644 --- a/files.lua +++ b/files.lua @@ -37,12 +37,13 @@ Files.read = function(filename) do local file_contents = _FILE_CACHE[filename] if file_contents then - return file_contents + return file_contents or nil end end - if filename == 'stdin' then + if filename == 'stdin' or filename == '-' then local contents = io.read('*a') Files.spoof('stdin', contents) + Files.spoof('-', contents) return contents end local file = io.open(filename) @@ -52,7 +53,7 @@ Files.read = function(filename) local contents = file:read("*a") file:close() _FILE_CACHE[filename] = contents - return contents + return contents or nil end local match, gsub do @@ -71,7 +72,7 @@ Files.exists = function(path) if _SPOOFED_FILES[path] then return true end - if path == 'stdin' then + if path == 'stdin' or path == '-' then return true end if run_cmd("ls " .. tostring(sanitize(path))) then @@ -82,7 +83,7 @@ end Files.list = function(path) if not (_BROWSE_CACHE[path]) then local files - if _SPOOFED_FILES[path] or path == 'stdin' then + if _SPOOFED_FILES[path] or path == 'stdin' or path == '-' then _BROWSE_CACHE[path] = { path } @@ -107,14 +108,14 @@ if ok then if _SPOOFED_FILES[path] then return true end - if path == 'stdin' or raw_file_exists(path) then + if path == 'stdin' or path == '-' or raw_file_exists(path) then return true end return false end Files.list = function(path) if not (_BROWSE_CACHE[path]) then - if _SPOOFED_FILES[path] or path == 'stdin' then + if _SPOOFED_FILES[path] or path == 'stdin' or path == '-' then _BROWSE_CACHE[path] = { path } -- cgit v1.2.3