44 lines
1.3 KiB
Clojure
44 lines
1.3 KiB
Clojure
#!/usr/bin/env bb
|
|
|
|
(require '[clojure.core.match :refer [match]]
|
|
'[babashka.cli :as cli]
|
|
'[clojure.pprint :as pp]
|
|
'[clojure.tools.logging :as l]
|
|
'[babashka.process :refer [shell check process] :as p])
|
|
|
|
(def cli-spec
|
|
{:spec
|
|
{:archive-limit {:coerce :int
|
|
:alias :n
|
|
:validate #(pos? %)
|
|
:default 3
|
|
:desc "Number of archives to save at a time."}
|
|
:device {:coerce :string
|
|
;; :validate fs/exists?
|
|
:require true
|
|
:desc "Dataset to be archived and rolled back."}
|
|
:previous-roots
|
|
{:coerce :string
|
|
:default "/persist/previous"
|
|
:desc "The path under which previous roots will be stored."}
|
|
:error-fn
|
|
(fn [{:keys [spec type cause msg option] :as data}]
|
|
(when (= :org.babashka/cli type)
|
|
(case cause
|
|
:require
|
|
(println
|
|
(format "Missing required argument: %s\n" option))))
|
|
(System/exit 1))}})
|
|
|
|
(defmacro with-echoed-shell-commands [& body]
|
|
(let [print-cmd #(println (str "+ " (str/join (:cmd %))))]
|
|
`(binding [p/*defaults* {:pre-start-fn ~print-cmd}]
|
|
~@body)))
|
|
|
|
(defn -main [opts]
|
|
(pp/pprint opts)
|
|
(with-echoed-shell-commands
|
|
(shell "mount")))
|
|
|
|
(-main (cli/parse-opts *command-line-args* cli-spec))
|