borkdude / jet

CLI to transform between JSON, EDN, YAML and Transit using Clojure

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Read function from file, via `-F`?

dotemacs opened this issue · comments

I went ahead and implemented a comparison of jq tutorial in jet:

https://gist.github.com/dotemacs/6c9185cca3cf59486b55471b1e965ed5

If you look at the last example:

https://gist.github.com/dotemacs/6c9185cca3cf59486b55471b1e965ed5#add-the-parent-commit-urls-to-the-above

writing that query at the shell prompt, without paren completion/matching, is quickly going to become cumbersome/error prone.

What do you think of the idea to add the switch -F (and something appropriate in long format e.g. --fn-from-file), which would read a function from file?

Why would you want to write a function in a file?

Arguably, your $EDITOR has probably the best support for paren matching/completion. So that way you can write the function in a file and the pass it in as a command line option e.g.

cat foo.json | jet -i json -o json -F /tmp/fn.clj

Just an idea, what do you think?

Thanks

At this point you might just want to use babashka probably?

@dotemacs I know a better solution: -f / --func accepts a file path as well. Just check if the expression happens to refer to an existing file, if not, execute it as a Clojure expression.

@dotemacs I know a better solution: -f / --func accepts a file path as well. Just check if the expression happens to refer to an existing file, if not, execute it as a Clojure expression.

Oh, I love that! :)

Added it, just let me think of a nice way to test. PR coming up shortly.