l3nz / cli-matic

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

WIP: Make it usable from nodejs #83

Closed lins05 closed 2 years ago

lins05 commented 4 years ago

Right now when using from nodejs it fails to compile due to lack of "plank" namespace. I made some quick & dirty fix to make it work. If you think this could be of value to the project I can tidy up the code (e.g to make it work for both plank and node).

l3nz commented 4 years ago

I like the idea! Of course it must keep working on both Planck and Node.

1 - Platform changes should live in an namespace of their own to be imported conditionally

2 - why the change in core?

3 - add checks through the main run script - whatever works in Planck should work in node

4 - add docs and check as per Deploy.md

lins05 commented 4 years ago

1 - Platform changes should live in an namespace of their own to be imported conditionally

For clj/cljs we can use reader conditionals, but any tips how to detect whether it's nodejs or plank?

2 - why the change in core?

Because unlike jvm, a nodejs process doesn't necessarily exit after the main function is finished - it only exists when all the event loop has no more io callbacks to run. So it's very likely the main function sets up the event loop, and in such case cli-matic shall not call exit explicitly. Maybe I shall include this in code comment.

l3nz commented 4 years ago

For clj/cljs we can use reader conditionals, but any tips how to detect whether it's nodejs or plank?

MAybe something like: https://github.com/l3nz/cli-matic/blob/e4303c722429371a324cdfdb0d9fc758c331d6d3/src/cli_matic/optionals.clj#L19

Because unlike jvm, a nodejs process doesn't necessarily exit after the main function is finished - it only exists when all the event loop has no more io callbacks to run. So it's very likely the main function sets up the event loop, and in such case cli-matic shall not call exit explicitly. Maybe I shall include this in code comment.

In general I would expect CLI-matic to shutdown at the end of the called function; there are a number of tricks we could use for waiting (eg core.async) but they require external libraries and/or are not available in all cases. I am opening up a separate bug for a wrapper to defer termination - see #84.

l3nz commented 4 years ago

BTW see #85

alexisvincent commented 3 years ago

Would be awesome to see this working! Is there significant work to be done to get this to work?

l3nz commented 2 years ago

Never completed, so I'm closing this without merging.