Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLI for listing available versions of a library #17

Merged
merged 30 commits into from
Apr 3, 2022

Conversation

teodorlu
Copy link
Contributor

@teodorlu teodorlu commented Apr 2, 2022

Effort to solve #16.

Ready for review!

Improvement suggestions much welcome.

Design

Example usage:

$ neil dep versions :lib org.clojure/clojure :limit 4
:lib org.clojure/clojure :version 1.11.1-rc1
:lib org.clojure/clojure :version 1.11.0
:lib org.clojure/clojure :version 1.11.0-rc1
:lib org.clojure/clojure :version 1.11.0-beta1

Make sure listing versions works well by piping into CLI for adding a dependency. The neil add dep CLI takes an option map - which works great. We simply produce lines like :lib org.clojure/clojure :version 1.11.0.

neil add dep currently doesn't support input on stdin, only CLI arguments. To get around this, we can use xargs.

neil dep versions org.clojure/clojure | fzf | xargs neil add dep

Where fzf can be replaced by any command that selects a single line from stdin and prints that line on stdout.

Option without xargs (not implemented, only an idea)

If we wanted to avoid the need for xargs, we could support the - convention for reading input from stdin:

neil dep versions org.clojure/clojure | fzf | neil add dep -

If neil dep add can take stdin input, it also makes sense for it to be able to add multiple dependencies, one per line.

Remaining work / open questions.

  • Doesn't work for git deps. What should we do here? Not sure.
    • Decision: print error and exit if coordinates are not found on Clojars or Maven. We can extend to support git deps later if we want to.
  • Remove teodor-notes.org before merging
  • Consider removing comment about Clojars API lacking a way to limit the number of recent versions
    • @borkdude what do you prefer here?
    • I removed the comment.
  • Remove neil dep add CLI entrypoint
  • Squash or cleanup git history
    • The current history is a mess. Rebasing might not make sense.
    • I'm leaning towards squashing into a single commit. @borkdude - preferences?
  • Remove printlns and pprints.

@teodorlu teodorlu changed the title CLI for listing available versions of a library (#16) CLI for listing available versions of a library Apr 2, 2022
neil Outdated Show resolved Hide resolved
Comment on lines -34 to +57
(-> (curl/get (format "https://search.maven.org/solrsearch/select?q=g:%%22%s%%22+AND+a:%%22%s%%22&rows=1"
(-> (curl/get (format "https://search.maven.org/solrsearch/select?q=g:%s+AND+a:%s&rows=1"
Copy link
Contributor Author

@teodorlu teodorlu Apr 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The %%22s turn up as double quotes in the Maven search URL. They seem to correspond to searching for "org.clojure" rather than org.clojure as group. Both seem to produce identical results.

src/babashka/neil.clj Outdated Show resolved Hide resolved
@teodorlu
Copy link
Contributor Author

teodorlu commented Apr 3, 2022

I'm just going to remove neil dep add entrypoint. That's a different topic.

@teodorlu
Copy link
Contributor Author

teodorlu commented Apr 3, 2022

The git? logic currently doesn't make any sense. You don't specify a version :sha to list versions.

(defn dep-versions [opts]
  (let [lib (or (:lib opts)
                (first (:cmds opts)))
        lib (symbol lib)
        git? (or (:sha opts)
                 (:latest-sha opts))
        versions (if git?
                   ::todo
                   (or (seq (clojars-versions lib opts))
                       (seq (mvn-versions lib opts))))]
    (doseq [v versions]
      (println :lib lib :version v))))

@teodorlu
Copy link
Contributor Author

teodorlu commented Apr 3, 2022

New solution: look for coordinates on Clojars / Maven. If the coordinates are not found, print error and return with an error code.

(defn dep-versions [opts]
  (let [lib (or (:lib opts)
                (first (:cmds opts)))
        lib (symbol lib)
        versions (or (seq (clojars-versions lib opts))
                     (seq (mvn-versions lib opts)))]
    (if-not versions
      (binding [*out* *err*]
        (println "Unable to find" lib "on Clojars or Maven.")
        (System/exit 1))
      (doseq [v versions]
        (println :lib lib :version v)))))

@teodorlu teodorlu marked this pull request as ready for review April 3, 2022 09:01
neil Outdated Show resolved Hide resolved
Comment on lines +374 to +382

dep

- versions: lists available versions of :lib. Currently suppports Clojars/Maven coordinates, no
Git deps.

Options:

:lib - Fully qualified symbol. :lib keyword may be elided when lib name is provided as first option.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just copied your existing help text structure.

Comment on lines +400 to +401
(let [opts (parse-opts opts)
opts (with-default-deps-edn opts)]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love how you're working with options. Great fit for Clojure, great fit for Unix CLIs.

@borkdude
Copy link
Contributor

borkdude commented Apr 3, 2022

@teodorlu Is this PR ready?

About: Squash or cleanup git history
Not needed, I'll just squash/merge, after you remove anything you'd still like to remove.

Screen Shot 2022-04-03 at 21 27 46

@teodorlu
Copy link
Contributor Author

teodorlu commented Apr 3, 2022

@borkdude If squash & merge is fine - go for it!

@borkdude borkdude merged commit c3319be into babashka:main Apr 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants