deps-new

leifericf 2022-02-17T19:43:45.334209Z

Hello, friends! I’m relatively new to Clojure, and I first got introduced to Leiningen via “Clojure for the Brave and True.” Today, I spent a couple of hours setting up the tools clojure/`clj` on macOS and Windows, and also trying out clj-new and deps-new. It works well, but I’m struggling to grok the man page for clojure/`clj`, and mentally “map” the synopsis from the man page to the example deps-new commands. Because the synopsis in the man page for clojure/`clj` is a bit alien and dense to me, and I’m not sure how to read it correctly. More specifically, in the command clojure -Tnew app :name myusername/mynewapp, if I try to break it down into separate “pieces,” why is there no space between -T and new, as would be the case with most other command-line utilities. Is app a function name, and/or a parameter to -Tnew? Why is :name a keyword, but not app? Why is there a / between myusername and mynewapp if this is not a path, and is this one parameter or two? I’m trying to see how these “pieces” correspond to the synopsis in the man page (see screenshot). But I’m thoroughly confused, so I would appreciate it if someone could explain this to me as if I’m a first-grader with a learning disability. I apologize in advance for asking very basic stuff, but I want to ensure I understand.

Ben Sless 2022-02-17T20:14:22.614059Z

Calling clojure cli with T invokes a tool aliased as the string following that T, everything else is arguments to the tool

Ben Sless 2022-02-17T20:17:20.135399Z

You can see the command on the left maps to the 3rd option in the man page

👍 1
seancorfield 2022-02-17T20:26:01.788029Z

-T is like -X in that it invokes a specific Clojure function and passes the command-line arguments as a hash map. -T is "tool" mode and implicitly uses :paths ["."] :replace-deps ... for building the classpath. -X is "exec" mode and uses the regular classpath, based on your deps.edn file.

seancorfield 2022-02-17T20:27:10.687739Z

Both options can take aliases, e.g., -T:foo uses the alias :foo when identifying dependencies and other data (such as default namespace etc). -Tbar is a special form that uses an installed tool called bar rather than an alias.

👍 2
seancorfield 2022-02-17T20:27:44.149189Z

clojure -Ttools invokes the built-in tool called tools (which handles core tool-related functionality).

seancorfield 2022-02-17T20:29:33.315449Z

clojure -Ttools install lib/name '{... dependency ...}' :as tool-name invokes the install function in the tools tool's default namespace and passes a hash map with two keys (`:as` and lib/name) and that downloads the dependency and installs it under the tool-name for use with -T.

💡 1
seancorfield 2022-02-17T20:30:41.756299Z

So, going back to your Q: clojure -Tnew app :name myusername/mynewapp invokes the app function in the default namespace of the tool installed as new and passes it a hash map {:name 'myusername/mynewapp}

💡 1
seancorfield 2022-02-17T20:31:30.760529Z

deps-new declares its default namespace for tool usage here: https://github.com/seancorfield/deps-new/blob/develop/deps.edn#L6

👀 1
seancorfield 2022-02-17T20:31:52.881499Z

So clojure -Tnew app ... invokes org.corfield.new/app specifically.

seancorfield 2022-02-17T20:32:41.656779Z

myusername/mynewapp is a qualified symbol name (just as io.github.seancorfield/deps-new is in the clojure -Ttools install ... command).

👍 1
seancorfield 2022-02-17T20:33:49.353079Z

-T and -X treat the command-line arguments after the initial function name as key/value pairs that are parsed as EDN (sort of a superset of JSON that matches Clojure more closely, support symbols, keywords, hash maps, vectors, etc).

💡 1
seancorfield 2022-02-17T20:34:09.590619Z

Does that help @leif.eric.fredheim?

💯 1
leifericf 2022-02-17T21:37:03.982959Z

Amazing! Thanks, @seancorfield! I think what threw me off is how :name myusername/mynewapp is equivalent to {:name 'myusername/mynewapp}, and -T and -X treat the command-line arguments after the initial function name as key/value pairs. I also did not understand that -T invoked “another tool installed within the tool,” and how new in -Tnew is an alias to that tool, and app is a function within that tool. It makes a lot more sense now! Although I must admit that the synopsis in the man page is still quite difficult to read and understand.

seancorfield 2022-02-17T22:22:49.838979Z

The guide and the reference are more expansive and may be better background reading: https://clojure.org/guides/deps_and_cli (reference is linked from that)

👀 1