 (defn name-endpoint-map->choice-list [name-endpoint-map]
   (map vector (iterate inc 1) name-endpoint-map))
 
-(defn print-discovered-devices [name-endpoint-map]
+(defn print-discovered-devices [name-endpoint-map opts]
   (if (empty? name-endpoint-map)
-    (println "(No devices)")
+    ((:print opts) "(No devices)")
     (doseq [[choice-number [bonjour-name _]] (name-endpoint-map->choice-list name-endpoint-map)]
-      (println (str "[" choice-number "] " (bonjour-name->display-name bonjour-name))))))
+      ((:print opts) (str "[" choice-number "] " (bonjour-name->display-name bonjour-name))))))
 
 (defn discover-and-choose-device
   "Looks for Ambly WebDAV devices advertised via Bonjour and presents
   a simple command-line UI letting user pick one, unless
   choose-first-discovered? is set to true in which case the UI is bypassed"
-  [choose-first-discovered?]
+  [choose-first-discovered? opts]
   (let [reg-type "_http._tcp.local."
         name-endpoint-map (atom (sorted-map))
         mdns-service (JmDNS/create)


(defn start-reading-messages
  "Starts a thread reading inbound messages."
  [repl-env]
  (.start
        (Thread.
          #(try
            (let [rv (read-messages (:in @(:socket repl-env)) (:response-promise repl-env))]
              (when (= :eof rv)
                (close-socket @(:socket repl-env))))
            (catch IOException e

                   (deliver resp-promise :eof))
                 :eof)
      (= c 1) (do
                ((:print-no-newline opts) (str sb))
                ((:flush opts))
                (recur (StringBuilder.) (.read in)))
      (= c 0) (do
                (deliver @response-promise (str sb))
