|
37 | 37 | "/usr/local/bin:" ;; homebrew
|
38 | 38 | (get sys-env "PATH"))}))))
|
39 | 39 |
|
40 |
| -(defn exit [status & [msg]] |
41 |
| - (when msg (println msg)) |
42 |
| - (when-not (env :is-dev) (System/exit status))) |
| 40 | +(defn exit |
| 41 | + ([status] (exit [status nil])) |
| 42 | + ([status msg] |
| 43 | + (when msg (println msg)) |
| 44 | + (when-not (env :is-dev) (System/exit status)))) |
43 | 45 |
|
44 | 46 | ;; paths
|
45 | 47 | (defn json-config-file-path
|
|
71 | 73 | (let [{:keys [applications devices keyboard-type input-sources tos froms modifiers layers simlayers ;; raws
|
72 | 74 | main simlayer-threshold templates profiles]} conf]
|
73 | 75 | (if (nil? profiles)
|
74 |
| - (profiles/parse-profiles (:profiles d/conf-data)) |
| 76 | + (profiles/parse-profiles (:profiles @d/conf-data)) |
75 | 77 | (profiles/parse-profiles profiles))
|
76 | 78 | (update-static-conf :applications applications)
|
77 | 79 | (update-static-conf :devices devices)
|
|
177 | 179 | [["-h" "--help"]
|
178 | 180 | ["-V" "--version"]
|
179 | 181 | ["-l" "--log"]
|
| 182 | + [nil "--where-is-my-config"] |
180 | 183 | ["-c" "--config PATH" "Config PATH"
|
181 | 184 | :parse-fn abs-path
|
182 | 185 | :validate [(fn [path]
|
183 |
| - (let [path (abs-path path)] |
184 |
| - (and (fs/exists? path) |
185 |
| - (fs/file? path) |
186 |
| - (fs/readable? path)))) |
| 186 | + (and (fs/exists? path) |
| 187 | + (fs/file? path) |
| 188 | + (fs/readable? path))) |
187 | 189 | "Make sure the file is exits and readable"]]
|
188 | 190 | ["-d" "--dry-run"]
|
189 | 191 | ["-A" "--dry-run-all"]])
|
|
201 | 203 | {:action "exit-with-message"
|
202 | 204 | :ok? true
|
203 | 205 | :exit-message (help-message summary)}
|
| 206 | + (:where-is-my-config options) |
| 207 | + {:action "show-config-path" |
| 208 | + :ok? true} |
204 | 209 | ;; version
|
205 | 210 | (:version options)
|
206 |
| - {:action "exit-with-message" |
207 |
| - :ok? true |
208 |
| - :exit-message "0.5.3"} |
| 211 | + {:action "exit-with-message" |
| 212 | + :ok? true |
| 213 | + :exit-message "0.5.6"} |
209 | 214 | ;; log
|
210 | 215 | (:log options)
|
211 | 216 | {:action "log"
|
|
229 | 234 | [& args]
|
230 | 235 | (let [{:keys [action ;; options
|
231 | 236 | exit-message ok? config dry-run dry-run-all]} (validate-args args)]
|
232 |
| - (when exit-message |
233 |
| - (case action |
234 |
| - "run" (do (parse (or config (edn-config-file-path)) dry-run dry-run-all) |
235 |
| - (exit (if ok? 0 1) exit-message)) |
236 |
| - "log" (do (open-log-file) |
237 |
| - (exit 0)) |
238 |
| - "exit-with-message" (exit (if ok? 0 1) exit-message) |
239 |
| - "errors" (exit (if ok? 0 1) exit-message) |
240 |
| - "default" (exit (if ok? 0 1) exit-message))))) |
| 237 | + (case action |
| 238 | + "run" (do (parse (or config (edn-config-file-path)) dry-run dry-run-all) |
| 239 | + (exit (if ok? 0 1) exit-message)) |
| 240 | + "show-config-path" (exit 0 (or config (edn-config-file-path))) |
| 241 | + "log" (do (open-log-file) (exit 0)) |
| 242 | + "exit-with-message" (exit (if ok? 0 1) exit-message) |
| 243 | + "errors" (exit (if ok? 0 1) exit-message) |
| 244 | + "default" (exit (if ok? 0 1) exit-message)))) |
241 | 245 |
|
242 | 246 | (comment
|
243 | 247 | (-main)
|
|
246 | 250 | (-main "-l")
|
247 | 251 | (-main "--log")
|
248 | 252 | (-main "--config" "./")
|
| 253 | + (-main "--where-is-my-config") |
249 | 254 | (-main "-c" "./")
|
250 | 255 | (-main "-dc" "./")
|
251 | 256 | (-main "-dc" "~/.config/karabiner.edn")
|
252 | 257 | (-main "-dc" "~/.config/karabiner.test.edn")
|
| 258 | + (-main "-c" "~/.nixpkgs/modules/yqrashawn/home-manager/dotfiles/karabiner.edn") |
253 | 259 | (-main "-d")
|
254 | 260 | (-main "-V")
|
255 | 261 | (-main "--version"))
|
0 commit comments