From e21c782f7f56da1435171bfa13e195db7d5c2752 Mon Sep 17 00:00:00 2001 From: Toshiki Takeuchi Date: Thu, 5 Mar 2020 19:19:55 +0900 Subject: [PATCH] Fix a non-empty command with allow-empty-command option --- src/clj_sub_command/core.cljc | 2 +- test/clj_sub_command/core_test.cljc | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/clj_sub_command/core.cljc b/src/clj_sub_command/core.cljc index 771df3b..7bc7f5a 100644 --- a/src/clj_sub_command/core.cljc +++ b/src/clj_sub_command/core.cljc @@ -339,7 +339,7 @@ scmds (set (map :cmd command-specs)) scmd (scmds cmd) cands (candidates cmd scmds) - error (when-not (or scmd allow-empty-command) + error (when-not (or scmd (and allow-empty-command (empty? cmd))) (str "Unknown command: " (pr-str (or cmd "")) (when (seq cands) (str "\n\n" (candidate-message cands))))) diff --git a/test/clj_sub_command/core_test.cljc b/test/clj_sub_command/core_test.cljc index c04ac8f..ff2245c 100644 --- a/test/clj_sub_command/core_test.cljc +++ b/test/clj_sub_command/core_test.cljc @@ -94,4 +94,9 @@ (str "Commands: " (s/join \, (map :cmd specs)))))] (is (nil? (:errors m))) (is (= (:options-summary m) "Options: --alpha|--beta")) - (is (= (:commands-summary m) "Commands: command1,command2"))))) + (is (= (:commands-summary m) "Commands: command1,command2"))) + (let [m (parse-cmds ["command3"] + [] + [["command1"] ["command2"]] + :allow-empty-command true)] + (is (= (count (:errors m)) 1)))))