Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

initial main cli #28

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 1 addition & 0 deletions deps.edn
Original file line number Diff line number Diff line change
@@ -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"}
Expand Down
30 changes: 30 additions & 0 deletions src/scicloj/clay/v2/main.clj
Original file line number Diff line number Diff line change
@@ -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)))))