1
0
mirror of https://github.com/janet-lang/janet synced 2025-11-18 16:25:11 +00:00

Add -e option to dst for executing inline scripts from the shell.

This commit is contained in:
bakpakin
2018-05-05 14:05:56 -04:00
parent 6b5c5ab0ad
commit d9e5019a71
3 changed files with 44 additions and 25 deletions

View File

@@ -10,24 +10,33 @@
(print "Options are:")
(print " -h Show this help")
(print " -v Print the version string")
(print " -e Execute a string of dst")
(print " -r Enter the repl after running all scripts")
(os-exit 0))
"v" (fn [] (print VERSION) (os-exit 0))
"r" (fn [] (:= *should-repl* true))
(os-exit 0)
1)
"v" (fn [] (print VERSION) (os-exit 0) 1)
"r" (fn [] (:= *should-repl* true) 1)
"e" (fn [i]
(:= *no-file* false)
(eval (get args (+ i 1)))
2)
})
(defn- dohandler [n]
(defn- dohandler [n i]
(def h (get handlers n))
(if h (h) (print "unknown flag -" n)))
(if h (h i) (print "unknown flag -" n)))
# Process arguments
(for [i 1 (length args)]
(var i 1)
(def lenargs (length args))
(while (< i lenargs)
(def arg (get args i))
(if (= "-" (string-slice arg 0 1))
(dohandler (string-slice arg 1 2))
(+= i (dohandler (string-slice arg 1 2) i))
(do
(:= *no-file* false)
(import arg))))
(import arg)
(++ i))))
(when (or *should-repl* *no-file*)
(print (string "Dst " VERSION " Copyright (C) 2017-2018 Calvin Rose"))