Fork me on GitHub
#boot
<
2016-04-29
>
chrisdevo00:04:47

Whatโ€™s the best way to set a command line bool option flag to default to false?

richiardiandrea00:04:48

@chrisdevo you can change the name and treat it as complement

richiardiandrea00:04:20

I don't think there is a way to set defaults for params in boot

micha14:04:34

@chrisdevo: i'd love to have that feature, but i couldn't figure out how to do it cleanly

micha14:04:44

like it would be cool to have something like if you have a flag --foo then boot could autogenerate the --no-foo flags too

micha14:04:16

but because of the way the cli argument parser we used works it doesn't seem straightforward to do

micha14:04:33

those would end up as diferent options in the options map

micha14:04:44

so how would you know which one is overriding which

dave14:04:09

@chrisdevo if the flag is not supplied, the value will be nil which is already falsey, so you can just do things like (when foo (do-something))

dave14:04:31

where foo will be "truthy" only if the user includes --foo at the CLI

dave14:04:56

in other words, bool option flags are already false by default

richiardiandrea15:04:43

@micha, in order to pass params to pod we need basically to transform them to strings and back right? I was thinking, maybe we just need a protocol on types with "marshal" and "unmarshal" to do it transparently instead of

... in a pod ...
(repl/launch-nrepl {:init-ns (symbol ~(str init-ns))
                    :port (Long/parseLong ~(str port))
...

richiardiandrea17:04:27

a case with clojure Symbol Keyword` would also work but this info needs to be present in the pod I guess, aka boot.pod/eval-in-caller, kind of backtick post-processing

richiardiandrea17:04:13

akin to custom resolvers I guess: (defquote shout-quote (comp symbol clojure.string/upper-case))

richiardiandrea17:04:52

going another step further:

(defn through-pod
  [datum]
  (condp = (class datum)
    clojure.lang.Symbol (symbol (str datum))))

(bt/defquote pod-quote (comp symbol through-pod))
Now I just need to know/discover where to put it in boot ๐Ÿ˜„

richiardiandrea17:04:58

so this works in the repl:

(require '[boot.from.backtick :as bt])

(defn through-pod
  [datum]
  (condp = (class datum)
    clojure.lang.Symbol (symbol datum)
    clojure.lang.Keyword (keyword datum)))

(bt/defquote pod-quote (comp symbol through-pod))

...
(pod/with-pod @pod
        (repl/launch-nrepl {:init-ns (~pod-quote-fn ~(str init-ns))
                            :port ~port
                            :server true
                            :middleware (:middleware pod/env)}))

micha17:04:56

@richiardiandrea: i don't understand what you mean about converting to strings?

micha17:04:19

you can send any clojure data as the expression for the pod to evaluate

micha17:04:06

the only thing you can't do is refer to names that don't exist in the pod or to objects that only exist in memory in one of the pods

richiardiandrea17:04:30

mmm...I thought no ๐Ÿ˜„ It throws an error if I evaluate:

(pod/with-pod @pod
        (repl/launch-nrepl {:init-ns ~init-ns
                            :port ~port
                            :server true
                            :middleware (:middleware pod/env)}))

richiardiandrea17:04:50

where init-ns is dev as symbol

micha17:04:58

i think you need to quote that, no?

micha17:04:08

:init-ns '~init-ns

richiardiandrea17:04:41

ok, so maybe I did not understand how it worked fully ๐Ÿ˜„

micha17:04:07

because the launch-nrepl thing is a function

micha17:04:45

also you need to require the namespaces in the pod

micha17:04:20

(pod/with-pod @pod
  (boot.repl/launch-nrepl ...

richiardiandrea17:04:23

yes I am doing that, just cut a bit..

richiardiandrea17:04:37

(pod/with-pod @pod
        (require '[boot.pod :as pod])
        (require '[boot.util :as util])
        (require '[boot.repl :as repl])
        (require '[clojure.tools.namespace.repl :as tnsr])

        (util/info "Launching %s...\n" ~pod-env)
        (util/info "Launching backend nRepl...\n")


        (apply tnsr/set-refresh-dirs (-> pod/env :directories))

        (repl/launch-nrepl {:init-ns '~init-ns
                            :port ~port
                            :server true
                            :middleware (:middleware pod/env)})

        (require 'dev)
        (require 'reloaded.repl)
        (reloaded.repl/go))

micha17:04:45

ah ok i see

richiardiandrea17:04:57

but it java.lang.ClassNotFoundException: org.clojure, compiling:(NO_SOURCE_PATH:0:0)

micha18:04:18

that seems like an issue with the middleware maybe?

micha18:04:42

the ~pod-env

micha18:04:51

that looks like it needs to be quoted

richiardiandrea18:04:18

so do I need to quote all the external symbols? Like port as well?

micha18:04:46

it's like when you make a macro

micha18:04:50

for example:

micha18:04:16

(defmacro foo [x]
  `(prn ~x))

richiardiandrea18:04:41

ah, understand, I need to capture the symbol outside

micha18:04:42

if you do (foo asdf) you get an error

micha18:04:53

but if you do (foo 100) it's ok

richiardiandrea18:04:03

still a problem but in this case I am missing something on the classpath maybe:

Launching backend nRepl...
nREPL server started on port 5600 on host 127.0.0.1 - 
:unknown "java.net.ServerSocket"
:unknown "clojure.lang.Atom"
:unknown "java.net.ServerSocket"
      clojure.lang.ExceptionInfo: clojure.tools.nrepl.server.Server
    data: {:file "/tmp/boot.user7459477259827150576.clj", :line 77}
java.lang.ClassNotFoundException: clojure.tools.nrepl.server.Server
                                ...                                        
     clojure.core/eval/invokeStatic                          core.clj: 3105

richiardiandrea18:04:36

but thanks that was useful

micha18:04:56

weird i've never seen the :unknown stuff before

richiardiandrea18:04:43

Only if you have one eye on the monitor simple_smile

Launching {:dependencies [[org.clojure/clojure "1.8.0"] [com.taoensso/timbre "4.3.1"] [aleph "0.4.1-beta3"] [bidi "1.24.0"] [yada "1.1.11"] [aero "1.0.0-beta2"] [com.stuartsierra/component "0.3.1"] [org.clojure/tools.namespace "0.2.10"] [reloaded.repl "0.2.1"] [prismatic/schema "1.0.4"] [org.clojure/core.async "0.2.374"] [org.clojure/tools.reader "0.10.0"] [org.clojure/tools.logging "0.3.1"] [org.slf4j/jcl-over-slf4j "1.7.13"] [org.slf4j/jul-to-slf4j "1.7.13"] [org.slf4j/log4j-over-slf4j "1.7.13"] [ch.qos.logback/logback-classic "1.1.3" :exclusions [org.slf4j/slf4j-api]] [org.clojure/tools.nrepl "0.2.12" :exclusions [[org.clojure/clojure]]]], :middleware [boot.from.io.aviso.nrepl/pretty-middleware], :source-paths #{"env/dev" "dev" "src/backend"}, :resource-paths #{"resources"}, :directories #{"env/dev" "dev" "src/backend" "resources"}}

richiardiandrea18:04:10

it is a sample app that I am porting to boot

richiardiandrea18:04:49

where is this :unknown stuff coming from lol

richiardiandrea20:04:31

Newbie question: should I be able to execute tasks in a pod?