|
5 | 5 | [path :refer [basename dirname join resolve]]
|
6 | 6 | [module :refer [Module]]
|
7 | 7 | [commander]
|
| 8 | + [wisp.package :refer [version]] |
8 | 9 |
|
9 | 10 | [wisp.string :refer [split join upper-case replace]]
|
10 | 11 | [wisp.sequence :refer [first second last count reduce rest
|
|
64 | 65 | (first operations)
|
65 | 66 | (rest operations)))
|
66 | 67 |
|
| 68 | +(defn parse-params |
| 69 | + [params] |
| 70 | + (let [options (-> commander |
| 71 | + (.version version) |
| 72 | + (.usage "[options] <file ...>") |
| 73 | + (.option "-r, --run" |
| 74 | + "compile and execute the file (same as wisp path/to/file.wisp)") |
| 75 | + (.option "-c, --compile" |
| 76 | + "compile given file and prints to stdout") |
| 77 | + (.option "-i, --interactive" |
| 78 | + "run an interactive wisp REPL (same as wisp with no params)") |
| 79 | + (.option "--print <format>" |
| 80 | + "use custom print output `expansion`,`forms`, `ast`, `js-ast` or (default) `code`" |
| 81 | + str |
| 82 | + "code") |
| 83 | + (.option "--no-map" |
| 84 | + "disable source map generation") |
| 85 | + (.parse params))] |
| 86 | + (conj {:no-map (not (:map options))} |
| 87 | + options))) |
| 88 | + |
67 | 89 | (defn main
|
68 | 90 | []
|
69 |
| - (let [options commander] |
70 |
| - (-> options |
71 |
| - (.usage "[options] <file ...>") |
72 |
| - (.option "-r, --run" "Compile and execute the file") |
73 |
| - (.option "-c, --compile" "Compile to JavaScript and save as .js files") |
74 |
| - (.option "-i, --interactive" "Run an interactive wisp REPL") |
75 |
| - (.option "--debug, --print <type>" "Print debug information. Possible values are `expansion`,`forms`, `ast` and `js-ast`") |
76 |
| - (.option "--no-map" "Disable source map generation") |
77 |
| - (.parse process.argv)) |
78 |
| - (set! (aget options "no-map") (not (aget options "map"))) ;; commander auto translates to camelCase |
79 |
| - (cond options.run (run (get options.args 0)) |
| 91 | + (let [options (parse-params process.argv) |
| 92 | + path (aget options.args 0)] |
| 93 | + (cond options.run (run path) |
80 | 94 | (not process.stdin.isTTY) (compile-stdin options)
|
81 | 95 | options.interactive (start-repl)
|
82 |
| - options.compile (compile-file (get options.args 0) options) |
83 |
| - options.args (run options.args) |
84 |
| - :else (start-repl) |
85 |
| - ))) |
| 96 | + options.compile (compile-file path options) |
| 97 | + path (run path) |
| 98 | + :else (start-repl)))) |
0 commit comments