babashka / neil

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

`neil add`: don't crash, instead print helptext #222

Closed teodorlu closed 1 month ago

teodorlu commented 1 month ago

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

Problem: neil add just crashes, giving the user some information would be more helpful

$ neil add
----- Error --------------------------------------------------------------------
Type:     clojure.lang.ExceptionInfo
Data:     {:type :org.babashka/cli, :wrong-input nil, :all-commands ("dep" "test" "build" "kaocha" "nrepl"), :cause :input-exhausted, :opts {:deps-file "deps.edn"}}
Location: /opt/homebrew/bin/neil:1703:3

----- Context ------------------------------------------------------------------
1699: (defn neil-test [{:keys [opts]}]
1700:   (neil-test/neil-test opts))
1701: 
1702: (defn -main [& _args]
1703:   (cli/dispatch
        ^--- 
1704:    [{:cmds ["add" "dep"] :fn dep-add :args->opts [:lib]}
1705:     {:cmds ["add" "test"] :fn add-cognitect-test-runner}
1706:     {:cmds ["add" "build"] :fn add-build}
1707:     {:cmds ["add" "kaocha"] :fn add-kaocha}
1708:     {:cmds ["add" "nrepl"] :fn add-nrepl}

----- Stack trace --------------------------------------------------------------
babashka.cli/dispatch-tree/fn--25816       - <built-in>
babashka.cli/dispatch-tree/error-fn--25819 - <built-in>
babashka.cli/dispatch-tree                 - <built-in>
babashka.cli/dispatch                      - <built-in>
babashka.neil/-main                        - /opt/homebrew/bin/neil:1703:3
babashka.neil/-main                        - /opt/homebrew/bin/neil:1702:1
babashka.neil                              - /opt/homebrew/bin/neil:1764:3
babashka.neil                              - /opt/homebrew/bin/neil:1763:1

Proposed solution for now: print the helptext

$ neil-dev add
Usage: neil <subcommand> <options>

Most subcommands support the options:
  --alias      Override alias name.
  --deps-file  Override deps.edn file name.

Subcommands:

add
  dep    Alias for `neil dep add`.
  test   adds cognitect test runner to :test alias.
  build  adds tools.build build.clj file and :build alias.
  kaocha adds kaocha test runner to :kaocha alias.
  nrepl  adds nrepl server to :nrepl alias.

dep
  add: Adds --lib, a fully qualified symbol, to deps.edn :deps.
    Run `neil dep add --help` to see all options.

  search: Search Clojars for a string in any attribute of an artifact
    Run `neil dep search --help` to see all options.

  upgrade: Upgrade libs in the deps.edn file.
    Run `neil dep upgrade --help` to see all options.

  versions: List available versions of a library (Clojars libraries only)
    Run `neil dep versions -h` to see all options.

  update: Alias for `upgrade`.

license
  list   Lists commonly-used licenses available to be added to project. Takes an optional search string to filter results.
  search Alias for `list`
  add    Writes license text to a file
    Options:
    --license The key of the license to use (e.g. epl-1.0, mit, unlicense). --license option name may be elided when license key is provided as first argument.
    --file    The file to write. Defaults to 'LICENSE'.

new
  Create a project using deps-new
    Run `neil new --help` to see all options.

version
  Commands for managing the :version key in the deps.edn project config.
    Run `neil version --help` to see all options.

test
  Run tests. Assumes `neil add test`. Run `neil test --help` to see all options.

Future work: consider subcommand-specific helptext.

neil add could possibly have its own helptext. This could also be considered for other subcommands, such as neil dep.