bunbun.dev/arg-handler.fnl

26 lines
743 B
Plaintext
Raw Normal View History

2024-09-16 23:02:15 -07:00
(set _G.port 16384)
(set _G.use-http false)
2024-09-16 23:03:07 -07:00
(local usage (: "Usage: %s [options]
Options:
-h, --help Show this help message and exit
-p, --port Set the port number for the server. Don't change this
unless you're running the server locally
--use-http Use http instead of https. Only recommended when running
the server locally
" :format (. arg 0)))
(for [i 1 (length arg)]
(tset arg i (: (. arg i) :gsub "^%-+" ""))
(if (or (= (. arg i) :h) (= (. arg i) :help))
(do
(print usage)
(os.exit))
(or (= (. arg i) :p) (= (. arg i) :port))
(do
(set _G.port (. arg (+ i 1)))
(set-forcibly! i (+ i 1)))
(= (. arg i) :use-http) (set _G.use-http true)))