aboutsummaryrefslogtreecommitdiff
path: root/files.moon
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2018-11-20 14:52:59 -0800
committerBruce Hill <bruce@bruce-hill.com>2018-11-20 14:54:40 -0800
commit2bbc035f5dcc3ecd62724b9d1de0e7e3ea902379 (patch)
tree34a83497f7570946b6252183b3e8fe0ce2010595 /files.moon
parentf30413853063483147d941ffccc4b663b71bc943 (diff)
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`
Diffstat (limited to 'files.moon')
-rw-r--r--files.moon15
1 files changed, 8 insertions, 7 deletions
diff --git a/files.moon b/files.moon
index 93a7342..4088980 100644
--- a/files.moon
+++ b/files.moon
@@ -25,17 +25,18 @@ Files.spoof = (filename, contents)->
-- Read a file's contents
Files.read = (filename)->
if file_contents = _FILE_CACHE[filename]
- return file_contents
- if filename == 'stdin'
+ return file_contents or nil
+ if filename == 'stdin' or filename == '-'
contents = io.read('*a')
Files.spoof('stdin', contents)
+ Files.spoof('-', contents)
return contents
file = io.open(filename)
return nil unless file
contents = file\read("*a")
file\close!
_FILE_CACHE[filename] = contents
- return contents
+ return contents or nil
{:match, :gsub} = string
@@ -49,14 +50,14 @@ sanitize = (path)->
Files.exists = (path)->
return true if _SPOOFED_FILES[path]
- return true if path == 'stdin'
+ return true if path == 'stdin' or path == '-'
return true if run_cmd("ls #{sanitize(path)}")
return false
Files.list = (path)->
unless _BROWSE_CACHE[path]
local files
- _BROWSE_CACHE[path] = if _SPOOFED_FILES[path] or path == 'stdin'
+ _BROWSE_CACHE[path] = if _SPOOFED_FILES[path] or path == 'stdin' or path == '-'
{path}
else run_cmd('find -L "'..path..'" -not -path "*/\\.*" -type f') or false
return _BROWSE_CACHE[path]
@@ -68,12 +69,12 @@ if ok
return if mode == 'file' or mode == 'directory' or mode == 'link' then true else false
Files.exists = (path)->
return true if _SPOOFED_FILES[path]
- return true if path == 'stdin' or raw_file_exists(path)
+ return true if path == 'stdin' or path == '-' or raw_file_exists(path)
return false
Files.list = (path)->
unless _BROWSE_CACHE[path]
- _BROWSE_CACHE[path] = if _SPOOFED_FILES[path] or path == 'stdin'
+ _BROWSE_CACHE[path] = if _SPOOFED_FILES[path] or path == 'stdin' or path == '-'
{path}
else
file_type, err = lfs.attributes(path, 'mode')