borkdude/carve

Clojure API

vemv opened this issue · 3 comments

vemv commented

In a similar vein to clj-kondo/clj-kondo#226, Carve could offer a clojure API.

Checking out

carve/src/carve/main.clj

Lines 64 to 80 in f499f65

(defn main
[& [flag opts & _args]]
(let [config-file (io/file ".carve/config.edn")
config (when (.exists config-file)
(edn/read-string (slurp config-file)))]
(if (and (not flag) (not config))
(binding [*err* *out*]
(println "No config found in .carve/config.edn.\nSee https://github.com/borkdude/carve#usage on how to use carve.")
1)
(do (when (and (not (= "--opts" flag)) (not config))
(throw (ex-info (str "Unrecognized option: " flag) {:flag flag})))
(let [opts (load-opts config opts)
format (-> opts :report :format)
report (impl/run! opts)]
(when format
(impl/print-report report format))
(if (empty? report) 0 1))))))
, a few things stand out as not very api-ish:

  • a println
  • CLI option parsing
  • Printing of reports (even when requesting edn) instead of returning edn directly

WDYT?

Thanks - V

I think that makes sense.

vemv commented

PR welcome?

Alright!