tools-deps

Discuss tools.deps.alpha, tools.build, and the clj/clojure command-line scripts! See also #depstar #clj-new
imre 2021-03-11T12:58:11.238400Z

Is there a way to launch clj completely ignoring the local deps.edn but using an alias from the user deps.edn?

imre 2021-03-11T13:01:24.238600Z

I suppose I could use replace-deps/paths in said alias...

borkdude 2021-03-11T13:02:22.238800Z

Yes, for tools unrelated to your main deps you should use this

imre 2021-03-11T13:03:55.239Z

Kinda clunky when I have a tool that I usually use together with my main deps but every once in a while I want to use it on its own

imre 2021-03-11T13:04:02.239200Z

Still doable

alexmiller 2021-03-11T13:41:42.239900Z

Working on such a thing now actually

imre 2021-03-11T13:50:06.240100Z

ooh nice one!

phronmophobic 2021-03-11T20:33:07.240800Z

I started using clojure cli a few months ago and I'm already sold on switching all my projects to work with deps.edn. I still feel clumsy trying to consume 3rd party tools like deps-deploy and depstar and was wondering if my mental model of how the cli is supposed to work is off. I organized my thoughts in this gist, https://gist.github.com/phronmophobic/5ae932b8769b6d03e5749e9a135b6374. Maybe it's useful as an experience report. Based on learning how to use the cli recently, I would be happy to suggest edits to the cli documentation, but I'm not sure if that would be helpful. Anyway, I know there's been lots of work and progress on the cli tools and the clojure cli has already improved my workflows. Thanks!

alexmiller 2021-03-11T20:47:20.242500Z

Yeah, I have some definite thoughts in this area, but it’s queued up behind other work

👍 1
alexmiller 2021-03-11T20:47:46.243200Z

More to do for sure!

seancorfield 2021-03-11T20:58:51.247400Z

@smith.adriane That explain option is an interesting idea. Being able to ask the CLI script to display what the various aliases resolve to and what the ultimate command execution would be could be very helpful for folks new to the CLI or even just new to a particular CLI tool.

seancorfield 2021-03-11T20:59:27.248100Z

It's partly why I added a :query true option to clj-new so it can tell you what it would do if you executed it for real.

👍 1
phronmophobic 2021-03-11T21:02:52.251200Z

yes seems generally useful • provides the data the cli “sees” which helps you form a mental model by flattening all of the different options and params into one piece of data • makes it easier to debug other’s cli commands since they can just provide the explain

phronmophobic 2021-03-11T21:05:12.253700Z

I think having a built in way to get the help text for a cli tool is a bigger win though since otherwise there’s no standard way to see examples or see the available options other than source code and github readmes (afaik)

alexmiller 2021-03-11T21:35:22.256700Z

I would really like to have something like: • a command that tells you help for a namespace (probably the ns doc string) • a command that tells you the functions in a namespace you can invoke (all public? all with particular meta? all doc'ed? filter to 1-arity? lots of open questions) • a command to give you help about a particular function (presumably the fn doc string) and then some of the debugging aids you mention would probably be helpful too

➕ 4
vlaaad 2021-03-12T08:22:53.276800Z

> A command that tells you the functions in a namespace you can invoke (all public? all with particular meta? all doc’ed? filter to 1-arity? lots of open questions) I’ve been thinking about this as well in the context of cli entry point for Reveal. I wanted to have a single entry point ns accessible both from code and from cli, but some functions that are definitely a public API don’t make sense to use from cli (if they are e.g. have to be composed with other functions). Given that, it made sense to use particular meta. There is also another question that’s not asked — how to show a short description of a function vs a full documentation. Given an ns, it makes sense to get some quick overview of what functions are there before diving into details of a particular function. There were a couple of options, and the most pragmatic to me seemed treating very first line of cli docstring as this short description. The whole code for that is here: https://github.com/vlaaad/reveal/blob/master/src/vlaaad/reveal.clj#L159-L182

eval2020 2021-03-13T17:02:07.297400Z

@vlaaad that’s similar to the approach I took for inclined:

clj -Sdeps '{:deps {eval/inclined {:git/url "<https://gitlab.com/eval/inclined.git>" :sha "a40aeeba2d471f19e83eeeceb3ebbc700f23185f"}}}' -M -m inclined.main -h

alexmiller 2021-03-11T21:47:26.257500Z

@borkdude did you ever re-try with latest cli?

borkdude 2021-03-11T21:51:06.258200Z

@alexmiller Yes, no problems so far, but I haven't worked on my own projects a lot today with which I had the problems. More on the weekend

alexmiller 2021-03-11T21:58:30.258700Z

thx, I'll probably hold off till next week to release stable anyways, so no rush

phronmophobic 2021-03-11T22:01:02.258800Z

> a command that tells you the functions in a namespace you can invoke (all public? all with particular meta? all doc'ed? filter to 1-arity? lots of open questions) Conceptually, I view choosing a function and specifying the arguments as orthogonal. The arglist is either a map for a function designed with cli -X in mind or a sequence in the general sense. It is a tricky problem since at some point you're better off just writing the command into a script instead of typing it at the command line. > a command that tells you help for a namespace (probably the ns doc string) I've used several of the cli "toolbelts" (aws, heroku, git) and started toolbelt projects at a few of the places I've worked. One of the reasons I think the clojure cli is particularly exciting is that it's potentially an open toolbelt. Maybe it would be better as a 3rd party library, but the idea of being able to find cli tools using the cli tool itself sounds appealing (eg. cli find linter to find linter tools). The syntax isn't consistent, but hopefully the idea makes sense. I also like the idea of being able to copy seancorfield's deps.edn into my .clojure/deps.edn and then run a command like cli ls to list all of the aliases and associated commands. These suggestions gloss over all the details of how the cli tool would be able to discover cli tools on the internet or from a deps.edn file, but adding discoverability makes it easier to find the right tool as a user and have your tools be found as an author.

seancorfield 2021-03-11T22:13:35.259Z

@smith.adriane

(! 847)-&gt; clj -A:deps
user=&gt; (require '[clojure.tools.deps.alpha :as t])
nil
user=&gt; (-&gt;&gt; (t/find-edn-maps) ((juxt :root-edn :user-edn :project-edn)) (t/merge-edns) :aliases (keys) (sort))
(:1.0 :1.1 :1.10 :1.10.0 :1.10.1 :1.10.2 :1.2 :1.3 :1.4 :1.5 :1.6 :1.7 :1.8 :1.9 :add-libs :bench :check :classes :closh :comp :decompile :deploy :deps :depstar :dev :eastwood :expect :graph :install :j14 :jar :jedi-time :liquid :master :measure :new :nrepl :outdated :pne :portal :prepl :readme :rebel :rebl :reflect :reveal :runner :socket :socket-rebl :socket-zero :spec2 :test :uberjar :dev/repl)

seancorfield 2021-03-11T22:14:00.259200Z

Just FYI, that's how to find all the available aliases in any given project or non-project context.

2
phronmophobic 2021-03-11T22:15:39.259500Z

My example is more of a hypothetical for someone picking up deps.edn. ie. How do I get up and running with a reasonable set of tools at my disposal?

seancorfield 2021-03-11T22:16:25.259700Z

Also, not sure if you're aware but :exec-args can be a keyword, and it is looked up as an alias to get the data structure that is the actual :exec-args map -- and tools can do the same thing (as depstar does and I believe deps-deploy soon will too).

seancorfield 2021-03-11T22:18:16.259900Z

Yeah, the absolute "getting started" (with deps) part is still a bit fiddly. My comment there is if you at least start with clj-new and create a new project that way, it'll already have the aliases you need for testing, building a JAR, deploying to Clojars etc.

seancorfield 2021-03-11T22:18:57.260100Z

But of course clj-new is opinionated about how to do those things and it's encoded in the built-in templates, and other new-project templates will be similarly opinionated in a different direction.

seancorfield 2021-03-11T22:19:10.260300Z

And of course there's also tools.build on the horizon.

phronmophobic 2021-03-11T22:19:14.260500Z

Yep, I use clj-new, but I have to either reuse the clj-new command that's in my bash history or go to the clj-new readme every time I use it

phronmophobic 2021-03-11T22:19:37.260700Z

I have the clj-new aliases from your deps.edn, but the clj-new docs don't actually use those

seancorfield 2021-03-11T22:19:43.260900Z

Which part(s) of the invocation are hard to remember?

phronmophobic 2021-03-11T22:20:58.261100Z

I don't create new projects that often and when I do, it's usually after copy and pasting the command from the github readme, so I never remember which keys are required

seancorfield 2021-03-11T22:21:30.261300Z

; my .clojure/deps.edn:
  :new {:extra-deps {com.github.seancorfield/clj-new {:mvn/version "1.1.264"}}
        :exec-fn clj-new/create
        :exec-args {:template lib}}
; the clj-new readme:
   :new {:extra-deps {com.github.seancorfield/clj-new
                         {:mvn/version "1.1.264"}}
            :exec-fn clj-new/create
            :exec-args {:template "app"}}
so the only difference is defaulting to app in the clj-new readme and lib in the .clojure file.

seancorfield 2021-03-11T22:22:15.261500Z

I could sync those up if I knew which was the more likely to be used 🙂

phronmophobic 2021-03-11T22:24:01.261700Z

fwiw, I think the docs for your dot-clojure, clj-new, and depstar are really good. It's mostly just that • there's no 0 arg version that makes sense • I use the tools infrequently enough that I don't remember the keyword names that are required • there's no way to figure out which options are available without going to the github readme page

phronmophobic 2021-03-11T22:24:55.261900Z

I'm not sure how cli tool authors provide a way to display options and examples except github readmes.

phronmophobic 2021-03-11T22:25:34.262100Z

the best work around that I can think of is for tools like clj-new to provide a 0 args version that prompts for any required/common options

phronmophobic 2021-03-11T22:26:00.262300Z

then I can just do clj -X:new and it can prompt me for the project name and template

phronmophobic 2021-03-11T22:27:55.262600Z

it's also totally possible that I'm doing it wrong. My intention was to use it like the aws cli toolbelt, but that might just be the wrong way.

seancorfield 2021-03-11T22:28:06.262800Z

(! 848)-&gt; clj -X:new
Usage:
  clojure -m clj-new.create template-name project-name options

or:
  clojure -X clj-new/create :template template-name :name project-name options

Any additional arguments are passed directly to the template.

The template-name may be:
* app - create a new application based on deps.edn
* lib - create a new library based on deps.edn
* template - create a new clj template based on deps.edn

👍 1
seancorfield 2021-03-11T22:28:39.263Z

I agree that isn't quite as consistent and helpful as it could be.

seancorfield 2021-03-11T22:29:23.263200Z

(part of the problem there is not being able to tell how something was invoked since that information is gone by the time the tool is invoked)

seancorfield 2021-03-11T22:30:12.263700Z

So clj-new would need to introspect the available aliases, see if :new was available and what it was aliased to, and then somehow weave that into the help.

seancorfield 2021-03-11T22:30:52.263900Z

Since you could be doing clojure -Sdeps '...' -X clj-new.create ... and not even have an alias available.

phronmophobic 2021-03-11T22:31:16.264100Z

actually, the help text for clj -X:new is exactly what I need. I guess I just never tried it. 😳

phronmophobic 2021-03-11T22:34:39.264300Z

hmm, actually, neither of the example commands work when I copy and paste them into the terminal. I guess that's since the cli tool doesn't know how the command was invoked as you were saying. It does solve my specific problem for clj-new though since I now have a way to look up the options without going to the github readme.

seancorfield 2021-03-11T22:39:19.264600Z

I will update the help so it's a bit "smarter" about things...

seancorfield 2021-03-11T22:42:27.264800Z

https://github.com/seancorfield/clj-new/issues/55 -- feel free to add more notes there.

👍 1
souenzzo 2021-03-11T23:59:37.266700Z

Can clj -Spath add an option emit all paths as canonical-path ? It will allow to create a classpath and invoke the java command from anydir