                'figwheel.repl/print-output
                (string/join "," (distinct (map name (:client-print-to config)))))))
 
+(defn get-repl-options [{:keys [options args inits repl-options] :as cfg}]
+  (assoc (merge (dissoc options :main)
+                repl-options)
+         :inits
+         (into
+          [{:type :init-forms
+            :forms (when-not (empty? args)
+                     [`(set! *command-line-args* (list ~@args))])}]
+          inits)))
+
+(defn get-repl-env-options [{:keys [repl-env-options ::config] :as cfg}]
+  (let [repl-options (get-repl-options cfg)]
+    (merge
+     (select-keys config
+                  [:ring-server
+                   :ring-server-options
+                   :ring-stack
+                   :ring-stack-options
+                   :ring-handler])
+     repl-env-options ;; from command line
+     (select-keys repl-options [:output-to :output-dir]))))
+
+(defn config-finalize-repl-options [cfg]
+  (let [repl-options (get-repl-options cfg)
+        repl-env-options (get-repl-env-options cfg)]
+    (assoc cfg
+           :repl-options repl-options
+           :repl-env-options repl-env-options)))
+
 #_(config-connect-url {::build-name "dev"})
 
 (defn update-config [cfg]

    (let [config-edn (process-figwheel-main-edn
                      (fetch-figwheel-main-edn cfg))]
      (-> cfg
          (update :repl-env-options
                  merge (select-keys config-edn
                                     [:ring-server
                                      :ring-server-options
                                      :ring-stack
                                      :ring-stack-options
                                      :ring-handler]))
          (update ::config merge config-edn)))))

(defn- config-merge-current-build-conf [{:keys [::extra-config ::build] :as cfg}]

                     (merge-with (fn [a b] (if b b a)) % (:config build))
                     extra-config)))

(defn host-port-arg? [arg]
  (and arg (re-matches #"(.*):(\d*)" arg)))

(defn update-server-host-port [config [f address-port & args]]
  (if (and (#{"-s" "--serve"} f) address-port)
    (let [[_ host port] (host-port-arg? address-port)]
      (cond-> config
        (not (string/blank? host)) (assoc-in [:ring-server-options :host] host)
        (not (string/blank? port)) (assoc-in [:ring-server-options :port] (Integer/parseInt port))))
    config))

;; targets options
(defn- config-main-ns [{:keys [ns options] :as cfg}]
