Fork me on GitHub
#kaocha
<
2019-08-26
>
plexus10:08:02

@jvtrigueros that's not currently implemented, but is straightforward with a plugin.

plexus10:08:17

quick untested example:

plexus10:08:20

(ns jvtrigueros.kaocha-plugins
  (:require [clojure.string :as str]))

(defn- accumulate [m k v]
  (update m k (fnil conj []) v))

(defn- parse-binding [s]
  (let [[k & vs] (str/split s #"=")
        v (str/join "=" vs)]
    [k v]))

(def cli-opts
  [nil "--binding" "Configure a dynamic binding, syntax dynamic.var/name=edn-value".
   :parse-fn parse-binding
   :assoc-fn accumulate])

(defplugin jvtrigueros.kaocha-plugins/cli-bindings
  (cli-options [opts]
    (conj opts cli-opts))

  (config [config]
    (let [bindings (get-in config [:kaocha/cli-options :binding])]
      (update config :kaocha/bindings #(into (or % {}) bindings)))))

plexus10:08:07

put that under src/ and try it out with kaocha --plugin jvtrigueros.kaocha-plugins/cli-bindings --binding my.var=[1,2,3] --print-config

plexus12:08:50

It would perhaps even be better to just have --binding take an edn map

jvtrigueros12:08:50

Sweet! Thanks!

plexus13:08:26

ah and you'll have to :refer [defplugin] 🙂

jvtrigueros13:08:14

Lemme give it a shot. Essentially I want to toggle some var when testing locally vs ci

plexus14:08:39

ok, in that case I would also look at the features that aero gives you. e.g. create a tests-ci.edn, containing #merge #include "tests.edn" {:kaocha/bindings {...}}

plexus14:08:09

and then run bin/kaocha --config-file tests-ci.edn on CI

plexus14:08:03

actually this makes me think we could do some cool stuff with aero's profiles, having a --profile cli flag, and defaulting to a profile of :ci when CI=true (which travis/circle/... all set)

jvtrigueros14:08:42

Ah I didn’t know I could do this. Thanks!