Last active
June 7, 2019 18:40
-
-
Save hlship/58651f64d8d4e128038dd947326740a9 to your computer and use it in GitHub Desktop.
Sample Joker script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env joker | |
(ns script | |
(:require [joker.tools.cli :as cli] | |
[joker.os :as os] | |
[joker.strconv :refer [atoi]])) | |
(def opts | |
[["-d" "--defcon VALUE" "Set DEFCON level" | |
:parse-fn atoi | |
:validate [#(<= 1 % 5) "level must be 1 to 5"]] | |
["-v" "--version" "Show version information"] | |
["-h" "--help" "Show this summary"]]) | |
(defn show-options | |
[summary errors] | |
(println "norad OPTIONS\n") | |
(println summary) | |
(when errors | |
(println "\nErrors:") | |
(run! println errors))) | |
(defn set-defcon | |
[value] | |
(println "Setting DEFCON to" value)) | |
(let [{:keys [options summary errors]} (cli/parse-opts *command-line-args* opts) | |
{:keys [help defcon version]} options] | |
(cond | |
errors | |
(do | |
(show-options summary errors) | |
(os/exit -1)) | |
help | |
(show-options summary nil) | |
version | |
(println "version: 1") | |
(some? defcon) | |
(set-defcon defcon) | |
:else | |
(do | |
(show-options summary ["Must specify a value for --defcon"]) | |
(os/exit -1)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment