diff --git a/CHANGELOG.md b/CHANGELOG.md index 66f9a8b2..30881d9a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,9 @@ # Change Log All notable changes to this project will be documented in this file. This change log follows the conventions of [keepachangelog.com](http://keepachangelog.com/). +## [2-alpha50] +- adds main cli: `clojure -M:dev -m scicloj.clay.v2.main` + ## [2-alpha49] - 2023-12-04 - fixed broken welcome message on `start!` - fixed the preparation of :kind/map - just print where possible diff --git a/deps.edn b/deps.edn index 8fd98070..b49af918 100644 --- a/deps.edn +++ b/deps.edn @@ -1,5 +1,6 @@ {:paths ["src" "resources"] :deps {org.clojure/clojure {:mvn/version "1.11.1"} + org.clojure/tools.cli {:mvn/version "1.0.219"} com.cnuernber/charred {:mvn/version "1.033"} carocad/parcera {:mvn/version "0.11.6"} org.antlr/antlr4-runtime {:mvn/version "4.7.1"} diff --git a/src/scicloj/clay/v2/main.clj b/src/scicloj/clay/v2/main.clj new file mode 100644 index 00000000..4707b158 --- /dev/null +++ b/src/scicloj/clay/v2/main.clj @@ -0,0 +1,30 @@ +(ns scicloj.clay.v2.main + "command line interface" + (:require [clojure.edn :as edn] + [clojure.tools.cli :as cli] + [scicloj.clay.v2.api :as api])) + +;; TODO: option validation should be done by the API +(def cli-options + [["-s" "--source-path PATHS" + :validate [sequential? (str "paths should be a sequence like " (pr-str ["notebooks"]))] + :default-desc (pr-str ["notebooks"]) + :parse-fn edn/read-string] + ["-t" "--target-dir DIR" :default-desc "docs"] + ["-h" "--help"]]) + +(defn -main + "Invoke with `clojure -M:dev -m scicloj.claykind.main --help` to see options" + [& args] + (let [{:keys [options summary arguments errors]} (cli/parse-opts args cli-options) + {:keys [help]} options] + (cond help (println "Clay" \newline + "Description: Clay evaluates Clojure namespaces into Markdown" \newline + "Options:" \newline + summary) + errors (do (println "ERROR:" errors) + (System/exit -1)) + :else (do (api/make! (merge (when (seq arguments) + {:source-path (vec arguments)}) + options)) + (System/exit 0)))))