Fork me on GitHub
#tools-deps
<
2022-10-15
>
Chase17:10:59

I'm curious how folks run multiple aliases that each have their own :main-opts . It's my understanding that only the last alias's main opts are run. So what would you do if you want to run something like clj -M:repl:server where both repl and server aliases have opts?

Chase17:10:43

I'm currently just running the aliases individually in a separate terminal but I imagine there might be a more efficient way

Chase17:10:16

haha, I did a search of the channel and it looks like I asked the same question over a year ago. Time flies! It seems the answer is I just can't do what I was attempting but I'll leave the question here in case things have changed or someone can recommend a better workflow

seancorfield20:10:50

You can write your own function that launches both things and have an alias for that.

seancorfield20:10:43

Personally, I never start a server from the command-line if I'm developing - I always start everything from the repl

skylize22:10:39

If the built in clojure repl is enough, you can -r as one of your main opts to also launch the repl.

1
Chase19:10:03

Thanks folks. I usually connect my editor through a nrepl so not sure the built in one will work. I have wanted to move to a more repl based workflow for starting servers and such so this is a good time to start. That is one of the things that libraries like Component, Integrant, Mount, etc. help with too right?

seancorfield19:10:24

I'm not talking about the built-in one. I start nREPL from the command-line, connect my editor to that, then start my web server or applications from within the editor, using that REPL connection.

seancorfield19:10:46

Just to clarify what I'm suggesting.

Chase19:10:15

Yep, I gotcha. I was responding to both of ya with the same comment

1
Chase19:10:11

So I made a dev alias that loads in a dev/user.clj file that I setup like so:

(ns user                                                                                         
  (:require                                                                                      
    [ring-app.core :refer [-main]]))                                                             
                                                                                                 
(defonce server (-main))                                                                         
                                                                                                 
(defn start []                                                                                   
  (.start server))                                                                               
                                                                                                 
(defn stop []                                                                                    
  (.stop server))                                                                                
                                                                                                 
(defn restart []                                                                                 
  (stop)                                                                                         
  (start))                                                                                       
                                                                                                 
(comment                                                                                         
  (start)                                                                                        
  (stop)                                                                                         
  (restart)                                                                                      
  ,)
where (-main) starts my jetty server. The thing I can't figure out is how to refactor this such that the server isn't automatically started when invoking clj -M:dev:repl . What should I do instead of the defonce ?

practicalli-johnny11:10:00

I have an alias that loads dev/user.clj via an extra path. In the user namespace I have everything in a comment form, except for the ns form that defines any requires So namespaces are loaded, but code that initiates anything is in a comment The only exceptions to that rule are println statements to show useful information on REPL startup and global logging context for mulog. Here is what I am using on my current project (it uses integrant, but thats abstracted to the system namespace so any component system could be used - or none) https://gist.github.com/practicalli-john/904b5d9ae398aaec2649b50b98a709eb

seancorfield16:10:28

☝️:skin-tone-2: Yup, that's what I have, essentially. I have a -main so that I can "run" my dev startup via -M but I can safely load the ns without it doing anything.

Chase18:10:40

Sounds good. I just moved the server invocation to the comment block and changed the start, stop, and restart functions to take that server as an argument.

1