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

Support custom Jack-in command lines #2152

Closed
PEZ opened this issue Apr 10, 2023 · 0 comments
Closed

Support custom Jack-in command lines #2152

PEZ opened this issue Apr 10, 2023 · 0 comments
Labels

Comments

@PEZ
Copy link
Collaborator

PEZ commented Apr 10, 2023

A way to make Calva Jack-in very flexible is to allow for a custom command line. Something like this setting in a connect sequence:

"customJackInCommandLine": "npx shadow-cljs -d <CIDER-NREPL-VERSION> watch :app some-arg-1 some-arg-2"

Would construct a fixed command line, which substitutes the cider-nrepl dependency version. So it would become:

npx shadow-cljs -d 0.28.5 watch :app some-arg-1 some-arg-2

This would allow the user to quite easily reach shadow-cljs features that the current jack-in convenience shuts you out from. The facility doesn't stop at letting us provide custom options to common Clojure tools, though, it would allow for any command line, including calling custom scripts.

Calva could make the following substitutions available to the command line construction:

From configuration:

  • <NREPL-VERSION>
  • <CIDER-NREPL-VERSION>
  • <CIDER-PIGGIEBACK-VERSION>
  • <NREPL-PORT-FILE>

Collected at Jack-in:

  • <PROJECT-ROOT-PATH>
  • <LEIN-PROFILES>
  • <LEIN-LAUNCH-ALIAS>
  • <CLJ-ALIASES>
  • <CLJS-LAUNCH-BUILDS>

With this the above command line could be:

"customJackInCommandLine": "npx shadow-cljs -d <CIDER-NREPL-VERSION> watch <CLJS-LAUNCH-BUILDS> some-arg-1 some-arg-2"

Making it still allow the user to decide at Jack-in time which shadow-build to watch. The plural substitutions would be provided as a comma separated list. So :app,:test e.g.

Just like with any Jack-in, the command line will be executed with the jackInEnv provided in Calva configuration.

Here's an example Babashka script that doesn't start a REPL at all, just echoes the aliases and cider nrepl version:

#!/usr/bin/env bb

(require '[clojure.string :as str])

(defn parse-args [args]
  (loop [args args
         parsed {}]
    (if (empty? args)
      parsed
      (let [[flag value & rest-args] args]
        (case flag
          "--aliases" (recur rest-args (assoc parsed :aliases value))
          "--cider-nrepl-version" (recur rest-args (assoc parsed :cider-nrepl-version value))
          (do (println "Unknown parameter:" flag) (System/exit 1)))))))

(defn process-args [args]
  (let [aliases (str/split (:aliases args) #",")
        cider-nrepl-version (:cider-nrepl-version args)]
    (println "Aliases:")
    (doseq [alias aliases]
      (println alias))
    (println "CIDER nREPL version:" cider-nrepl-version)))

(def parsed-args (parse-args *command-line-args*))

(when (= *file* (System/getProperty "babashka.file"))
  (process-args parsed-args))

Please comment with your thoughts on this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant