blob: ae4a3805585c46eb300693e2bdddc3754c251e40 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
(ns backup
(:require [clojure.edn :as edn]
[datomic.require :as req]
[datomic.cli :as cli]))
(def commands
"Map of command names to descriptions of command arguments."
{"backup"
{:f 'datomic.backup-cli/backup
:named #{{:long-name :from-db-uri :required true :doc "URI for backup source"}
{:long-name :to-backup-uri :required true :doc "URI for backup destination"}}
:positional [:from-db-uri :to-backup-uri]}
"list"
{:f 'datomic.backup-cli/list-backups
:named #{{:long-name :backup-uri :required true :doc "backup URI"}}
:positional [:backup-uri :to-db-uri]}
"verify"
{:f 'datomic.backup-cli/verify-backup
:named #{{:long-name :backup-uri :required true :doc "URI of backup"}
{:long-name :read-all :required true :doc "Verify that every segment is readable" :coerce #(boolean (edn/read-string %))}
{:long-name :t :required true :doc "Point in time (t) to verify" :coerce #(Long. %)}}
:positional [:backup-uri :read-all :t]}
"restore"
{:f 'datomic.backup-cli/restore
:named #{{:long-name :from-backup-uri :required true :doc "URI for restore source"}
{:long-name :to-db-uri :required true :doc "URI for restore destination"}
{:long-name :t :doc "Point in time (t) to restore, defaults to most recent"
:default nil :coerce #(Long. %)}}
:positional [:from-backup-uri :to-db-uri :t]}})
(defn -main
[& [command & cli-args]]
(if-let [{:keys [f named positional vararg]} (get commands command)]
(let [args (cli/parse-or-exit! command cli-args named positional vararg)]
(try
(when-let [result (req/require-and-run f args)]
(println result))
(catch Throwable t
(.printStackTrace t)
(cli/fail (.getMessage t))))
(when @cli/exit-after-command
(System/exit (if @cli/failed 1 0))))
(binding [*out* *err*]
(println (str "Bad command: \"" command "\"."))
(System/exit 2))))
|