-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathedn_diff.clj
More file actions
executable file
·58 lines (48 loc) · 1.77 KB
/
edn_diff.clj
File metadata and controls
executable file
·58 lines (48 loc) · 1.77 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/env bb
(ns edn-diff
(:require [babashka.process :refer [shell]]
[clojure.data :as data]
[clojure.edn :as edn]
[clojure.string :as str]
[clojure.pprint :as pprint]
[lambdaisland.deep-diff2 :as diff2]
[shell-smith.core :as smith]))
(def usage "
edn-diff
Usage:
edn-diff [-a|-r] [-e] [-b=<branch>] <edn-file>
edn-diff -h
Options:
-b --branch=<branch> Branch used to compare [default: master]
-a --added-only Show only added compared to branch
-r --removed-only Show only removed compared to branch
-e --edn-output Format output in edn for scripting
-h --help Show help
")
(def config (smith/config usage :name "end_diff"))
(defn read-edn-from-branch [branch file-path]
(-> (shell {:out :string} "git" "show" (str branch ":" file-path))
:out
edn/read-string))
(defn -main [& _args]
(let [{:keys [branch edn-file added-only removed-only edn-output]} (smith/config usage)
current-branch (str/trim (:out (shell {:out :string} "git" "branch" "--show-current")))
current-data (read-edn-from-branch current-branch edn-file)
other-data (read-edn-from-branch branch edn-file)]
(cond
added-only
(let [diff (first (data/diff current-data other-data))]
(if edn-output
(prn diff)
(pprint/pprint diff)))
removed-only
(let [diff (second (data/diff current-data other-data))]
(if edn-output
(prn diff)
(pprint/pprint diff)))
:else
(if edn-output
(prn (data/diff current-data other-data))
(diff2/pretty-print (diff2/diff current-data other-data))))))
(when (= *file* (System/getProperty "babashka.file"))
(apply -main *command-line-args*))