babashka / neil

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

`neil new`: print built-in templates #166

Closed teodorlu closed 1 year ago

teodorlu commented 1 year ago

Please answer the following questions and leave the below in as part of your PR.

Generated helptext

In this PR; the generated helptext is:

$ neil-dev new -h

Usage: neil new [template] [name] [target-dir] [options]

Runs the org.corfield.new/create function from deps-new.
Usage: neil new [template] [name] [target-dir] [options]

Runs the org.corfield.new/create function from deps-new.

All of the deps-new options can be provided as CLI options:

https://github.com/seancorfield/deps-new/blob/develop/doc/options.md

Both built-in and external templates are supported. Built-in templates use
unqualified names (e.g. scratch) whereas external templates use fully-qualified
names (e.g. io.github.kit/kit-clj).

Provided built-in templates are:

    app
    lib
    pom
    scratch
    template

If an external template is provided, the babashka.deps/add-deps function will be
called automatically before running org.corfield.new/create. The deps for the
template are inferred automatically from the template name. The following
options can be used to control the add-deps behavior:

  --local/root
    Override the :deps map to use the provided :local/root path.

  --git/url
    Override the :git/url in the :deps map. If no URL is provided, a template
    name starting with io.github or com.github is expected and the URL will
    point to GitHub.

  --git/tag
    Override the :git/tag in the :deps map. If no SHA or tag is provided, the
    latest tag from the default branch of :git/url will be used.

  --sha
  --git/sha
    Override the :git/sha in the :deps map. If no SHA or tag is provided, the
    latest tag from the default branch of :git/url will be used.

  --latest-sha
    Override the :git/sha in the :deps map with the latest SHA from the
    default branch of :git/url.

Examples:
  neil new scratch foo --overwrite
  neil new io.github.rads/neil-new-test-template foo2 --latest-sha

Should this be merged?

I'm not sure whether this is the way to go to look up valid values template values:

(defn- built-in-templates []
  (require 'org.corfield.new)
  (let [blacklist #{'create}]
    (->> (ns-publics 'org.corfield.new)
         (remove (fn [[sym _]] (contains? blacklist sym)))
         (into {}))))

deps-new could easily add another public var in org.corfield.new, and we'll happily assume it's a valid template.

Alternatives

165 solves this by linking to upstream documentation.

seancorfield commented 1 year ago

I think this is reasonable. Because of the -X:deps help/doc only "commands" will get added to this ns and it's very unlikely a new command would be added that isn't another built-in template.

teodorlu commented 1 year ago

@seancorfield OK! In that case, I'm in favor of merging.

teodorlu commented 1 year ago

@borkdude does the Clojure code look fine to you? Want any changes?

teodorlu commented 1 year ago

The print-new-help implementation got more complex with this PR. I'm open to suggestions, I feel like there's more nesting right now than neccessary, but I don't see any obvious ways to improve it.

borkdude commented 1 year ago

One minor comment, the rest looks good to me.