Browse Source

Fail gracefully when auto.lua is called on a file not in src/scripts

Bart van Strien 9 years ago
parent
commit
f4999bd2c7
1 changed files with 8 additions and 2 deletions
  1. 8 2
      src/scripts/auto.lua

+ 8 - 2
src/scripts/auto.lua

@@ -108,8 +108,14 @@ end
 for i, v in ipairs(arg) do
 	--run the auto function for every argument
 	--but do it with pcall, to catch errors
-	v = v:gsub("%.lua$", ""):gsub("^(.+)/", "") -- normalize input
-	local ok, err = pcall(auto, v)
+	local ok, err = true
+	v = v:gsub("^scripts/", "")
+	if v:match("/") then
+		ok, err = false, "not in scripts directory"
+	else
+		v = v:gsub("%.lua$", "") -- normalize input
+		ok, err = pcall(auto, v)
+	end
 	if not ok then
 		--inform people we've failed
 		print(v .. ": " .. err)