Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

How can I query the project group, name and version from a Leiningen project.clj file using only lein and simple command line utilities without modifying the project file?

I could not find anything useful in lein help, like executing code from the command line arguments.

I am thinking about writing a sed expression, but I am wondering if there is a simpler way using Leiningen.

question from:https://stackoverflow.com/questions/65852356/read-project-name-and-version-from-leiningen-project-clj-file

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
1.1k views
Welcome To Ask or Share your Answers For Others

1 Answer

This is fully(?) supported by Leiningen, sort of. In short:

$ (lein update-in :version pr -- version ; lein update-in :name pr -- version) | cut -d '"' -f 2

This works by abusing the update-in command to apply clojure.core/pr to the :version or :name project key. (You can see all project keys by using just a colon as the member to pr. The just-a-colon feature is described by lein help update-in.)

Leiningen requires an actual command too, in addition to update-in. Because pr returns nil, I suppose the updates damage the project map and make it unsuitable for real work. The above demo sidesteps the problem by using the version command to print Leiningen's own version.

Oddly, the printed version or name appears more than once; thus the cut command to take only the first quoted string on each line. We assume you haven't used quotes in your project name or version!

You can stack update-in's on one command line, but doing so makes the name and version harder to parse from the output.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...