Small wrapper around command line parsing with clojure.tools.cli
Combine named command line arguments from three sources:
Leiningen/Boot
[ndevreeze/cmdline "0.2.0"]
Clojure CLI/deps.edn
ndevreeze/cmdline {:mvn/version "0.2.0"}
Require:
(ns my.namespace
(:require [nl.nicodevreeze.cmdline :as cl]))
Define the command line options:
(def cli-options
[["-c" "--config CONFIG" "Config file"
:default "~/.config/my-program/my-program.edn"]
["-h" "--help" "Show this help"]
["-p" "--port PORT" "TCP port to use"
:default 1234 :parse-fn #(Integer/parseInt %)]
["-v" "--verbose" "Verbose output"]])
Define the worker function:
(defn do-script
"Main script"
[opt arguments ctx]
(when (:verbose opt)
(output-some-more)))
Small -main function:
(defn -main [& args]
(cl/check-and-exec "Description of script"
cli-options do-script args ctx))
Ctx/context can be anything, mostly a map.
$ lein midje
or:
$ lein repl (or start in Cider)
(use 'midje.repl)
(autotest)
Copyright © 2021 Nico de Vreeze
Distributed under the Eclipse Public License, the same as Clojure.
Can you improve this documentation?Edit on GitHub
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close