mirror of
				https://github.com/janet-lang/janet
				synced 2025-10-30 23:23:07 +00:00 
			
		
		
		
	Add option to cli interface to stop scanning options.
This commit is contained in:
		| @@ -5,22 +5,25 @@ | ||||
| (var *should-repl* :private false) | ||||
| (var *no-file* :private true) | ||||
| (var *raw-stdin* :private false) | ||||
| (var *handleopts* :private true) | ||||
|  | ||||
| # Flag handlers | ||||
| (def handlers :private { | ||||
|   "h" (fn []  | ||||
|     (print "usage: " (get args 0) " [options] scripts...") | ||||
|     (print "Options are:") | ||||
|     (print "  -h Show this help") | ||||
|     (print "  -v Print the version string") | ||||
|     (print "  -s Use raw stdin instead of getline like functionality") | ||||
|     (print "  -e Execute a string of dst") | ||||
|     (print "  -r Enter the repl after running all scripts") | ||||
|     (print `Options are: | ||||
|   -h Show this help | ||||
|   -v Print the version string | ||||
|   -s Use raw stdin instead of getline like functionality | ||||
|   -e Execute a string of dst | ||||
|   -r Enter the repl after running all scripts | ||||
|   -- Stop handling options`) | ||||
|     (os.exit 0) | ||||
|     1) | ||||
|   "v" (fn [] (print VERSION) (os.exit 0) 1) | ||||
|   "s" (fn [] (:= *raw-stdin* true) (:= *should-repl* true) 1) | ||||
|   "r" (fn [] (:= *should-repl* true) 1) | ||||
|   "-" (fn [] (:= *handleopts* false) 1) | ||||
|   "e" (fn [i]  | ||||
|     (:= *no-file* false) | ||||
|     (eval (get args (+ i 1))) | ||||
| @@ -36,7 +39,7 @@ | ||||
| (def lenargs (length args)) | ||||
| (while (< i lenargs) | ||||
|   (def arg (get args i)) | ||||
|   (if (= "-" (string.slice arg 0 1)) | ||||
|   (if (and *handleopts* (= "-" (string.slice arg 0 1))) | ||||
|     (+= i (dohandler (string.slice arg 1 2) i)) | ||||
|     (do | ||||
|       (:= *no-file* false) | ||||
|   | ||||
| @@ -119,4 +119,11 @@ | ||||
|  | ||||
| (assert (= (maxpath triangle) 25) `max triangle`) | ||||
|  | ||||
| (assert (= (string.join @["one" "two" "three"]) "onetwothree") "string.join 1 argument") | ||||
| (assert (= (string.join @["one" "two" "three"] ", ") "one, two, three") "string.join 2 arguments") | ||||
| (assert (= (string.join @[] ", ") "") "string.join empty array") | ||||
|  | ||||
| (assert (= (string.find "123" "abc123def") 3) "string.find positive") | ||||
| (assert (= (string.find "1234" "abc123def") nil) "string.find negative") | ||||
|  | ||||
| (end-suite) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Calvin Rose
					Calvin Rose