Fork me on GitHub
#tools-deps
<
2021-03-11
>
imre12:03:11

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

imre13:03:24

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

borkdude13:03:22

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

imre13:03:55

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

imre13:03:02

Still doable

Alex Miller (Clojure team)13:03:42

Working on such a thing now actually

imre13:03:06

ooh nice one!

phronmophobic20:03:07

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!

Alex Miller (Clojure team)20:03:20

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

👍 3
seancorfield20:03:51

@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.

seancorfield20:03:27

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.

👍 3
phronmophobic21:03:52

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

phronmophobic21:03:12

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)

Alex Miller (Clojure team)21:03:22

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

12
phronmophobic22:03:02

> 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.

seancorfield22:03:35

@smith.adriane

(! 847)-> clj -A:deps
user=> (require '[clojure.tools.deps.alpha :as t])
nil
user=> (->> (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)

seancorfield22:03:00

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

notbad 6
phronmophobic22:03:39

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?

seancorfield22:03:25

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).

seancorfield22:03:16

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.

seancorfield22:03:57

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.

seancorfield22:03:10

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

phronmophobic22:03:14

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

phronmophobic22:03:37

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

seancorfield22:03:43

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

phronmophobic22:03:58

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

seancorfield22:03:30

; 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.

seancorfield22:03:15

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

phronmophobic22:03:01

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

phronmophobic22:03:55

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

phronmophobic22:03:34

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

phronmophobic22:03:00

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

phronmophobic22:03:55

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.

seancorfield22:03:06

(! 848)-> 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

👍 3
seancorfield22:03:39

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

seancorfield22:03:23

(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)

seancorfield22:03:12

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.

seancorfield22:03:52

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

phronmophobic22:03:16

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

phronmophobic22:03:39

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.

seancorfield22:03:19

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

vlaaad08:03:53

> 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

eval202017:03:07

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

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

Alex Miller (Clojure team)21:03:26

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

borkdude21:03:06

@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

Alex Miller (Clojure team)21:03:30

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

souenzzo23:03:37

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