diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2019-09-20 14:40:15 -0700 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2019-09-20 14:40:15 -0700 |
| commit | 86c477343d8ae84fc99014a2cc4f844e9c688b9c (patch) | |
| tree | f8967fa4d23bc1cc4dfce1b4a9265d5b96db76be /nomsu.lua | |
| parent | 5396b2a9efe26cb146bf8991fc81b49e143bfb3d (diff) | |
Updates to error handling in the command line parsing and usage
printing.
Diffstat (limited to 'nomsu.lua')
| -rw-r--r-- | nomsu.lua | 27 |
1 files changed, 21 insertions, 6 deletions
@@ -1,7 +1,7 @@ NOMSU_VERSION = { 7, 0, - 0 + 1 } local clibtype = package.cpath:match("?%.(so)") or package.cpath:match("?%.(dll)") if NOMSU_PREFIX then @@ -29,9 +29,9 @@ end NOMSU_VERSION = List(NOMSU_VERSION) local Text = require('text') require('builtin_metatables') -local usage = [=[Nomsu Compiler - -Usage: (nomsu | lua nomsu.lua | moon nomsu.moon) [-V version] [--help | -h] [--version] [-O optimization level] [-v] [-c] [-s] [-d debugger] [--no-core] [(file | -t tool | -e "nomsu code..." | files... -- ) [nomsu args...]] +local EXIT_FAILURE = 1 +local EXIT_SUCCESS = 0 +local usage = [=[Nomsu Usage: nomsu [-V version] [--help | -h] [--version] [-O optimization level] [-v] [-c] [-s] [-d debugger] [--no-core] [(file | -t tool | -e "nomsu code..." | files... -- ) [nomsu args...]] OPTIONS -t <tool> Run a tool. @@ -101,13 +101,19 @@ local parser = re.compile([[ args <- {| (flag %sep)* }) local arg_string = table.concat(arg, sep) .. sep local args, err = parser:match(arg_string) -if not args or err or args.help then +if not args or err then if err then print("Didn't understand: " .. tostring(err)) end print(usage) os.exit(EXIT_FAILURE) end +if args.help then + print("Nomsu - A dynamically typed programming language with natural syntax and strong metaprogramming abilities.") + print("https://nomsu.org\n") + print(usage) + os.exit(EXIT_SUCCESS) +end if args.version then print(NOMSU_VERSION:joined_with(".")) os.exit(EXIT_SUCCESS) @@ -165,7 +171,7 @@ run = function() nomsu_environment:export("core") end local input_files = { } - if args.files then + if args.files and #args.files > 0 then local _list_1 = args.files for _index_0 = 1, #_list_1 do local f = _list_1[_index_0] @@ -258,6 +264,15 @@ run = function() end else local f = Files.read(filename) + if not f then + if filename:match("^-") then + print("Not a valid flag: " .. filename .. "\n") + print(usage) + else + print("File not found: " .. filename) + end + os.exit(EXIT_FAILURE) + end if filename:match("%.lua$") then f = LuaCode:from(Source(filename, 1, #f), f) end |
