From 045226ac540551fe8c6e1b0d9608b68e23988657 Mon Sep 17 00:00:00 2001 From: Michiel Borkent Date: Tue, 21 Apr 2020 15:08:20 +0200 Subject: [PATCH] [#371] fix arg parsing --- src/babashka/main.clj | 26 +++++++++++++++++--------- test/babashka/main_test.clj | 8 ++++++++ 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/src/babashka/main.clj b/src/babashka/main.clj index 2faf9c00..c7c65c48 100644 --- a/src/babashka/main.clj +++ b/src/babashka/main.clj @@ -22,8 +22,8 @@ [babashka.impl.socket-repl :as socket-repl] [babashka.impl.test :as t] [babashka.impl.tools.cli :refer [tools-cli-namespace]] - [babashka.impl.xml :as xml] [babashka.impl.transit :refer [transit-namespace]] + [babashka.impl.xml :as xml] [babashka.impl.yaml :refer [yaml-namespace]] [babashka.wait :as wait] [clojure.edn :as edn] @@ -115,17 +115,25 @@ (assoc opts-map :repl true))) ("--socket-repl") - (let [options (next options)] - (recur (next options) + (let [options (next options) + opt (first options) + opt (when-not (str/starts-with? opt "-") + opt) + options (if opt (next options) + options)] + (recur options (assoc opts-map - :socket-repl (or (first options) - "1666")))) + :socket-repl (or opt "1666")))) ("--nrepl-server") - (let [options (next options)] - (recur (next options) + (let [options (next options) + opt (first options) + opt (when-not (str/starts-with? opt "-") + opt) + options (if opt (next options) + options)] + (recur options (assoc opts-map - :nrepl (or (first options) - "1667")))) + :nrepl (or opt "1667")))) ("--eval", "-e") (let [options (next options)] (recur (next options) diff --git a/test/babashka/main_test.clj b/test/babashka/main_test.clj index d88115eb..74b67204 100644 --- a/test/babashka/main_test.clj +++ b/test/babashka/main_test.clj @@ -17,6 +17,14 @@ (edn/read-string (apply test-utils/bb (when (some? input) (str input)) (map str args)))) (deftest parse-opts-test + (is (= {:nrepl "1667", :classpath "src"} + (main/parse-opts ["--nrepl-server" "-cp" "src"]))) + (is (= {:socket-repl "1666", :expressions ["123"]} + (main/parse-opts ["--socket-repl" "-e" "123"]))) + (is (= {:socket-repl "1666", :expressions ["123"]} + (main/parse-opts ["--socket-repl" "1666" "-e" "123"]))) + (is (= {:nrepl "1666", :expressions ["123"]} + (main/parse-opts ["--nrepl-server" "1666" "-e" "123"]))) (is (= 123 (bb nil "(println 123)"))) (is (= 123 (bb nil "-e" "(println 123)"))) (is (= 123 (bb nil "--eval" "(println 123)")))