From ef0b3a6abb80128d88e485ff24940a674172b3f1 Mon Sep 17 00:00:00 2001 From: Timothy Pratley Date: Wed, 6 Dec 2023 23:02:40 -0800 Subject: [PATCH 1/2] initial main cli --- CHANGELOG.md | 3 +++ deps.edn | 1 + src/scicloj/clay/v2/main.clj | 30 ++++++++++++++++++++++++++++++ 3 files changed, 34 insertions(+) create mode 100644 src/scicloj/clay/v2/main.clj 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..626d93d0 --- /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-paths 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) + {:paths (vec arguments)}) + options)) + (System/exit 0))))) From 90827a13b6f4674c97806270b6fb2d74a2af2dcf Mon Sep 17 00:00:00 2001 From: Timothy Pratley Date: Wed, 6 Dec 2023 23:08:51 -0800 Subject: [PATCH 2/2] paths should be source-paths --- src/scicloj/clay/v2/main.clj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/scicloj/clay/v2/main.clj b/src/scicloj/clay/v2/main.clj index 626d93d0..4707b158 100644 --- a/src/scicloj/clay/v2/main.clj +++ b/src/scicloj/clay/v2/main.clj @@ -6,7 +6,7 @@ ;; TODO: option validation should be done by the API (def cli-options - [["-s" "--source-paths PATHS" + [["-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] @@ -25,6 +25,6 @@ errors (do (println "ERROR:" errors) (System/exit -1)) :else (do (api/make! (merge (when (seq arguments) - {:paths (vec arguments)}) + {:source-path (vec arguments)}) options)) (System/exit 0)))))