Skip to content

Commit

Permalink
Fix a non-empty command with allow-empty-command option
Browse files Browse the repository at this point in the history
  • Loading branch information
totakke committed Mar 5, 2020
1 parent e6cacba commit e21c782
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/clj_sub_command/core.cljc
Expand Up @@ -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)))))
Expand Down
7 changes: 6 additions & 1 deletion test/clj_sub_command/core_test.cljc
Expand Up @@ -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)))))

0 comments on commit e21c782

Please sign in to comment.