write to stderr instead of stdout

This commit is contained in:
leaf corcoran 2013-12-26 22:44:54 -08:00
parent 009bf8eff7
commit 18a3723f00

View File

@ -40,9 +40,12 @@ if opts.v then
end end
function print_help(err) function print_help(err)
if err then print("Error: "..err) end if err then
print(help:format(arg[0])) io.stderr:write("Error: ".. err .. "\n")
os.exit() end
io.stderr:write(help:format(arg[0]) .. "\n")
os.exit(1)
end end
function mkdir(path) function mkdir(path)
@ -70,9 +73,9 @@ function convert_path(path)
return (path:gsub("%.moon$", ".lua")) return (path:gsub("%.moon$", ".lua"))
end end
function msg(...) function log_msg(...)
if not opts.p then if not opts.p then
print(...) io.stderr:write(table.concat({...}, " ") .. "\n")
end end
end end
@ -302,7 +305,7 @@ function create_watcher(files)
dirs = remove_dups(dirs) dirs = remove_dups(dirs)
return coroutine.wrap(function() return coroutine.wrap(function()
print(("%s with inotify [%s]"):format(msg, plural(#dirs, "dir"))) io.stderr:write(("%s with inotify [%s]"):format(msg, plural(#dirs, "dir")) .. "\n")
local wd_table = {} local wd_table = {}
local handle = inotify.init() local handle = inotify.init()
@ -329,7 +332,7 @@ function create_watcher(files)
-- poll the filesystem instead -- poll the filesystem instead
local sleep = get_sleep_func() local sleep = get_sleep_func()
return coroutine.wrap(function() return coroutine.wrap(function()
print(("%s with polling [%s]"):format(msg, plural(#files, "file"))) io.stderr:write(("%s with polling [%s]"):format(msg, plural(#files, "file")) .. "\n")
local mod_time = {} local mod_time = {}
while true do while true do
@ -368,33 +371,34 @@ if opts.w then
local target = target_dir..convert_path(fname) local target = target_dir..convert_path(fname)
local success, err = compile_and_write(fname, target) local success, err = compile_and_write(fname, target)
if not success then if not success then
print() io.stderr:write(table.concat({
print("Error:", fname) "",
print(err) "Error: " .. fname,
print() err,
"\n",
}, "\n"))
else else
msg("Built:", fname, "->", target) log_msg("Built:", fname, "->", target)
end end
end end
print "\nQuitting..." io.stderr:write("\nQuitting...\n")
elseif opts.l then elseif opts.l then
for _, fname in pairs(files) do for _, fname in pairs(files) do
lint = require "moonscript.cmd.lint" lint = require "moonscript.cmd.lint"
local res = lint.lint_file(fname) local res = lint.lint_file(fname)
if res then if res then
print(res) io.stderr:write(res .. "\n\n")
print()
end end
end end
else else
for _, fname in ipairs(files) do for _, fname in ipairs(files) do
local success, err = compile_and_write(fname, target_dir..convert_path(fname)) local success, err = compile_and_write(fname, target_dir..convert_path(fname))
if not success then if not success then
print(fname, err) io.stderr:write(fname .. "\t" .. err .. "\n")
os.exit(1) os.exit(1)
else else
msg("Built", fname) log_msg("Built", fname)
end end
end end
end end