aboutsummaryrefslogtreecommitdiff
path: root/nomsu.moon
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2019-09-20 14:40:15 -0700
committerBruce Hill <bruce@bruce-hill.com>2019-09-20 14:40:15 -0700
commit86c477343d8ae84fc99014a2cc4f844e9c688b9c (patch)
treef8967fa4d23bc1cc4dfce1b4a9265d5b96db76be /nomsu.moon
parent5396b2a9efe26cb146bf8991fc81b49e143bfb3d (diff)
Updates to error handling in the command line parsing and usage
printing.
Diffstat (limited to 'nomsu.moon')
-rwxr-xr-xnomsu.moon24
1 files changed, 18 insertions, 6 deletions
diff --git a/nomsu.moon b/nomsu.moon
index b9e36c2..e6058bd 100755
--- a/nomsu.moon
+++ b/nomsu.moon
@@ -1,7 +1,7 @@
#!/usr/bin/env moon
-- This file contains the command-line Nomsu runner.
export NOMSU_VERSION
-NOMSU_VERSION = {7, 0, 0}
+NOMSU_VERSION = {7, 0, 1}
clibtype = package.cpath\match("?%.(so)") or package.cpath\match("?%.(dll)")
@@ -26,11 +26,11 @@ if clibtype == "dll"
NOMSU_VERSION = List(NOMSU_VERSION)
Text = require 'text'
require 'builtin_metatables'
+EXIT_FAILURE = 1
+EXIT_SUCCESS = 0
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...]]
+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.
@@ -96,11 +96,16 @@ parser = re.compile([[
})
arg_string = table.concat(arg, sep)..sep
args, err = parser\match(arg_string)
-if not args or err or args.help
+if not args or err
if err
print("Didn't understand: #{err}")
print usage
os.exit(EXIT_FAILURE)
+if args.help
+ 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)
if args.version
print(NOMSU_VERSION\joined_with("."))
os.exit(EXIT_SUCCESS)
@@ -139,7 +144,7 @@ run = ->
nomsu_environment\export("core")
input_files = {}
- if args.files
+ if args.files and #args.files > 0
for f in *args.files
if nomsu_name = f\match("^nomsu://(.*)%.nom")
path, err = package.searchpath(nomsu_name, package.nomsupath, "/")
@@ -204,6 +209,13 @@ run = ->
else
-- Just run the file
f = Files.read(filename)
+ if not f
+ if filename\match "^-"
+ print "Not a valid flag: "..filename.."\n"
+ print usage
+ else
+ print "File not found: "..filename
+ os.exit EXIT_FAILURE
if filename\match("%.lua$")
f = LuaCode\from(Source(filename, 1, #f), f)
env = nomsu_environment.new_environment!