mirror of
https://github.com/Reuh/candran.git
synced 2025-10-27 17:59:30 +00:00
Allow can and canc to read from stdin, check for errors, cleaner output
This commit is contained in:
parent
ab7472152f
commit
09ac497aed
7 changed files with 92 additions and 62 deletions
19
bin/can
19
bin/can
|
|
@ -5,12 +5,25 @@ local cmdline = require("lib.cmdline")
|
|||
local args = cmdline(arg)
|
||||
|
||||
if args.help or args.h then
|
||||
print("Candran interpreter version "..candran.VERSION.." by Reuh")
|
||||
print("Usage: "..arg[0].." [target=<target>] [options] filename")
|
||||
print("Candran "..candran.VERSION.." interpreter by Reuh")
|
||||
print("Usage: "..arg[0].." [options] filename")
|
||||
print("Use - instead of a filename to read from the standard input.")
|
||||
print("Default options:")
|
||||
for opt, val in pairs(candran.default) do
|
||||
if type(val) == "string" then val = val:gsub("\n", "\\n") end
|
||||
print((" %s=%q"):format(opt, val))
|
||||
end
|
||||
return
|
||||
end
|
||||
|
||||
if #args >= 1 then
|
||||
if arg[#arg] == "-" then
|
||||
local f, err = candran.load(io.read("*a"), "stdin", nil, args)
|
||||
if not f then
|
||||
io.stderr:write("can: "..err.."\n")
|
||||
os.exit(1)
|
||||
end
|
||||
f()
|
||||
elseif #args >= 1 then
|
||||
candran.dofile(args[1], args)
|
||||
else -- REPL
|
||||
print("Candran " .. candran.VERSION)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue