Moved print-usage out into support.

This commit is contained in:
Simon Brooke 2018-07-18 15:17:55 +01:00
parent 2ec8f4a928
commit 80860a264e
2 changed files with 13 additions and 42 deletions

View file

@ -2,6 +2,7 @@
:author "Simon Brooke"}
adl.main
(:require [adl-support.utils :refer :all]
[adl-support.print-usage :refer [print-usage]]
[adl.to-hugsql-queries :as h]
[adl.to-json-routes :as j]
[adl.to-psql :as p]
@ -52,43 +53,13 @@
])
(defn- doc-part
"An `option` in cli-options comprises a sequence of strings followed by
keyword/value pairs. Return all the strings before the first keyword."
[option]
(if
(keyword? (first option)) nil
(cons (first option) (doc-part (rest option)))))
(defn map-part
"An `option` in cli-options comprises a sequence of strings followed by
keyword/value pairs. Return the keyword/value pairs as a map."
[option]
(cond
(empty? option) nil
(keyword? (first option)) (apply hash-map option)
true
(map-part (rest option))))
(defn print-usage []
(println
(join
"\n"
(flatten
(list
(join
(list
"Usage: java -jar adl-"
(or (System/getProperty "adl.version") "[VERSION]")
"-SNAPSHOT-standalone.jar -options [adl-file]"))
"where options include:"
(map
#(let
[doc-part (doc-part %)
default (:default (map-part %))
default-string (if default (str "; (default: " default ")"))]
(str "\t" (join ", " (butlast doc-part)) ": " (last doc-part) default-string))
cli-options))))))
(defn usage [parsed-options]
"Show a usage message. `parsed-options` should be options as
parsed by [clojure.tools.cli](https://github.com/clojure/tools.cli)"
(print-usage
"adl"
parsed-options
{"adl-file" "An XML file conforming to the ADL DTD"}))
(defn -main
@ -97,16 +68,16 @@
(let [options (parse-opts args cli-options)]
(cond
(empty? args)
(print-usage)
(usage options)
(not (empty? (:errors options)))
(do
(doall
(map
println
(:errors options)))
(print-usage))
(usage options))
(-> options :options :help)
(print-usage)
(usage options)
true
(do
(let [p (:path (:options options))

View file

@ -587,8 +587,8 @@
:field
#(= "text-area" (widget-type (property-for-field % entity) application)))
"
{% script \"js/lib/node_modules/simplemde/dist/simplemde.min.js\" %}
{% style \"js/lib/node_modules/simplemde/dist/simplemde.min.css\" %}")
{% script \"/js/lib/node_modules/simplemde/dist/simplemde.min.js\" %}
{% style \"/js/lib/node_modules/simplemde/dist/simplemde.min.css\" %}")
(if
(child-with-tag
form