Created
June 12, 2018 01:41
-
-
Save rplevy/0487ed883fe615e1589521c37141457b to your computer and use it in GitHub Desktop.
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 plk -Sdeps {:deps,{inflections,{:mvn/version,"0.13.0"}}} | |
;; EXAMPLE USAGE: | |
;; | |
;; profiles2env profiles.clj > ~/cc-vars | |
;; . ~/cc-vars | |
(ns scripts.profiles2env | |
(:require [cljs.reader :as r] | |
[clojure.string :as str] | |
[goog.string :as gstr] | |
[goog.string.format] | |
[inflections.core :as inflections] | |
[planck.core :refer [slurp *command-line-args*]])) | |
(defn map->paths' [k v] | |
(let [k (name k)] | |
(if-not (map? v) | |
[[k v]] | |
(mapv (fn [k' v'] | |
(map->paths' (str k "__" (name k')) v')) | |
(keys v) | |
(vals v))))) | |
(defn map->paths [k v] | |
(->> (map->paths' k v) | |
flatten | |
(partition 2))) | |
(defn print-env-vars [k v] | |
(doseq [[k v] (map->paths k v)] | |
(println (gstr/format "export %s='%s'" | |
(-> k | |
inflections/underscore | |
str/upper-case) | |
v)))) | |
(let [data (-> *command-line-args* first slurp r/read-string :profiles/dev :env)] | |
(doseq [k (keys data)] | |
(print-env-vars k (get data k)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment