babashka / neil

A CLI to add common aliases and features to deps.edn-based projects
MIT License
372 stars 27 forks source link

After merging #216, `neil add` produces super long lines for certain aliases #224

Closed teodorlu closed 4 months ago

teodorlu commented 4 months ago

Problem

After merging #216 (which I wrote), certain aliases produce some super long lines, for example neil add build.

$ # per latest stable
$ neil add build
$ cat deps.edn 
{:deps {}
 :aliases
 {:build ;; added by neil
  {:deps {io.github.clojure/tools.build {:git/tag "v0.10.3" :git/sha "15ead66"}
          slipset/deps-deploy {:mvn/version "0.2.2"}}
   :ns-default build}}}
$ # on master, `:deps` keys for aliases are on the same line.
$ rm deps.edn 
$ rm build.clj 
$ neil-dev add build
$ cat deps.edn 
{:deps {}
 :aliases {:build {:deps {io.github.clojure/tools.build {:git/tag "v0.10.3", :git/sha "15ead66"}, slipset/deps-deploy {:mvn/version "0.2.2"}}
                   :ns-default build}}}

Proposed solution:

An alias is a map. If the alias map values themselves are maps, print them on separate lines.

Making this change, should produce the following deps.edn:

{:deps {}
 :aliases {:build {:deps {io.github.clojure/tools.build {:git/tag "v0.10.3", :git/sha "15ead66"},
                          slipset/deps-deploy {:mvn/version "0.2.2"}}
                   :ns-default build}}}

, where io.github.clojure/tools.build and slipset/deps-deploy are on their own lines.

borkdude commented 4 months ago

sounds good. maybe also add a test for it? I assumed such a test was already there

teodorlu commented 4 months ago

Yes, good idea.

teodorlu commented 4 months ago

After merging #225, this is the is the current behavior:

$ neil-dev add test && neil-dev add build && neil-dev add nrepl && neil-dev add kaocha
If you wish to create a `bin/kaocha` file, copy and run the following:

mkdir -p bin && \
echo '#!/usr/bin/env bash
clojure -M:kaocha "$@"' > bin/kaocha && \
chmod +x bin/kaocha
$ cat deps.edn 
{:deps {}
 :aliases {:test {:extra-paths ["test"]
                  :extra-deps {io.github.cognitect-labs/test-runner {:git/tag "v0.5.0"
                                                                     :git/sha "b3fd0d2"}}
                  :main-opts ["-m" "cognitect.test-runner"]
                  :exec-fn cognitect.test-runner.api/test}
           :build {:deps {io.github.clojure/tools.build {:git/tag "v0.10.3"
                                                         :git/sha "15ead66"}
                          slipset/deps-deploy {:mvn/version "0.2.2"}}
                   :ns-default build}
           :nrepl {:extra-deps {nrepl/nrepl {:mvn/version "1.1.2"}
                                cider/cider-nrepl {:mvn/version "0.49.0"}
                                refactor-nrepl/refactor-nrepl {:mvn/version "3.10.0"}}
                   :main-opts ["-m" "nrepl.cmdline" "--interactive" "--color" "--middleware" "[cider.nrepl/cider-middleware,refactor-nrepl.middleware/wrap-refactor]"]}
           :kaocha {:extra-deps {lambdaisland/kaocha {:mvn/version "1.91.1392"}}
                    :main-opts ["-m" "kaocha.runner"]}}}

I think the :main-opts line is a bit long, but I don't have any ideas on how to make it nicer. Perhaps the user may just edit the formatting if they don't like it later.

borkdude commented 4 months ago

Yeah, good enough