1
0
mirror of https://github.com/janet-lang/janet synced 2025-11-19 00:35:11 +00:00

More work on self hosting the client program.

This commit is contained in:
Calvin Rose
2018-02-07 13:19:34 -05:00
parent 3e1f031576
commit e047b39a87
9 changed files with 214 additions and 69 deletions

View File

@@ -1,7 +1,37 @@
(print (string "Dst " VERSION " Copyright (C) 2017-2018 Calvin Rose"))
(do
(var dorepl false)
(var nofile true)
# Flag handlers
(def handlers {
"h" (fn []
(print "usage: " (get args 0) " [options] scripts...")
(print "Options are:")
(print " -h Show this help")
(print " -v Print the version string")
(print " -r Enter the repl after running all scripts")
(exit 0))
"v" (fn [] (print VERSION) (exit 0))
"r" (fn [] (varset! dorepl true))
})
(defn dohandler [n]
(def h (get handlers n))
(if h (h) (print "unknown flag -" n)))
# Process arguments
(for [i 0 (length args)]
(print (get args i)))
(def nargs (length args))
(for [i 1 nargs]
(def arg (get args i))
(if (= "-" (string-slice arg 0 1))
(dohandler (string-slice arg 1 2))
(do
(varset! nofile false)
(require arg)
(init-loop))))
(init-repl)
(when (or dorepl nofile)
(print (string "Dst " VERSION " Copyright (C) 2017-2018 Calvin Rose"))
(init-repl))
)