l3nz / cli-matic

Compact, hands-free [sub]command line parsing library for Clojure.
Eclipse Public License 2.0
360 stars 28 forks source link

Returning lazy sequences from :runs throws - IPending is not IDeref #161

Closed NoahTheDuke closed 11 months ago

NoahTheDuke commented 11 months ago

Problem

In a subcommand :runs, functions that return lazy sequences throw. This includes functions like map and lazy-seq. Simplest example I could come up with:

(fn [& _] (lazy-seq (cons 1 ())))

This is because cli-matic.platform/isJvmPromise? checks if the returned value is an instance of IPending, which is used for realizing values, not for dereferencing (delivering, completing, calculating) values.

Repro

(let [cmd (fn [& _] (lazy-seq (cons 1 ())))
      setup {:command     "ipending-example"
             :opts        []
             :subcommands [{:command "foo"
                            :opts    []
                            :runs    cmd}]}]
  (run-cmd* setup ["foo"]))

Expected vs actual behavior

Should not throw, should default to 0.

Version / Platform

cli-matic 0.5.4, JVM 11, Clojure 1.11.1

l3nz commented 11 months ago

You are right. Merged.