Examples [skip ci]

This commit is contained in:
Michiel Borkent 2020-10-13 16:30:31 +02:00
parent 958944d785
commit 5fd975c312
2 changed files with 36 additions and 2 deletions

View file

@ -1,6 +1,6 @@
#!/usr/bin/env bb
(ns pom-version
(ns get-pom-version
{:author "Wilker Lucio"}
(:require [clojure.data.xml :as xml]
[clojure.string :as str]))
@ -17,7 +17,7 @@
(->>
(slurp path)
(xml/parse-str)
(xml-seq )
(xml-seq)
(filter #(tag-name? % "version"))
first
tag-content-str)))

34
examples/set_pom_version.clj Executable file
View file

@ -0,0 +1,34 @@
#!/usr/bin/env bb
;; usage: version.clj pom.xml 1.0.1
;; pom.xml:
;; <project>
;; <version></version>
;; </project>
;; prints to stdout:
;; <project>
;; <version>1.0.1</version>
;; </project>
(ns set-pom-version
{:author "Michiel Borkent"}
(:require [clojure.data.xml :as xml]))
(def pom-xml (first *command-line-args*))
(def version (second *command-line-args*))
(def xml (xml/parse-str (slurp pom-xml)))
(defn update-version [elt]
(if (= :version (:tag elt))
(assoc elt :content version)
elt))
(println
(xml/emit-str
(update xml :content
(fn [contents]
(map update-version contents)))))