diff options
| -rwxr-xr-x | src/blueprint | 10 | ||||
| -rw-r--r-- | src/lib/path.lua | 9 |
2 files changed, 15 insertions, 4 deletions
diff --git a/src/blueprint b/src/blueprint index 35b9c0e..ed8bc94 100755 --- a/src/blueprint +++ b/src/blueprint @@ -21,10 +21,14 @@ local commands = { local command = commands[arg[1]] if command then - local status, ret = pcall(command) + if os.getenv('BP_TRACE') == '1' then + command() + else + local status, ret = pcall(command) - if not status then - print('error: ' .. ret:gsub('^.+:%d+: (.+)$', '%1')) + if not status then + print('error: ' .. ret:gsub('^.+:%d+: (.+)$', '%1')) + end end else print([[blueprint <command> [options...] diff --git a/src/lib/path.lua b/src/lib/path.lua index 925f017..72ea94d 100644 --- a/src/lib/path.lua +++ b/src/lib/path.lua @@ -9,6 +9,7 @@ function Path:new(p) p = p:gsub("^%./", "") p = p:gsub("/[^/]+/%.%.", "") p = p:gsub("^[^/]+/%.%./", "") + p = p:gsub("^[^/]+/%.%.$", "") local path = { segments = p:split('/'), @@ -34,6 +35,9 @@ function Path:parent() end function Path:__tostring() + if #self.segments == 0 then + return "." + end return (self.is_absolute and "/" or "") .. table.concat(self.segments, "/") end @@ -132,8 +136,11 @@ function Path:is_parent_of(child) end function Path:relative_to_parent(path) - if not path:is_parent_of(self) then + if #path.segments > 0 and not path:is_parent_of(self) then + print('not parent', path, self) return nil + elseif #path.segments == 0 then + return Path:new(tostring(self)) end return Path:new(tostring(self):sub(#tostring(path) + 2)) |