Command Interpreter in Clojure?

173 views
Skip to first unread message

Nick Vargish

unread,
Feb 16, 2016, 8:18:46 AM2/16/16
to Clojure
My current project requires a command-line interpreter with limited functionality... For various non-technical reasons we can't expose bash to our users.

Our plans call for writing a console shell that will accept some limited command set, and Clojure would be the natural implementation language, since much of our functionality has been implemented in a Clojure library. We even have a command-line tool that exposes a lot of the functionality to shell scripts, but the parsing/function routing is quite primitive...

Any suggestions? Has anyone done work on a CLI implemented in Clojure?

Thanks,

Nick



Alan Thompson

unread,
Feb 16, 2016, 9:42:51 AM2/16/16
to clo...@googlegroups.com

--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clo...@googlegroups.com
Note that posts from new members are moderated - please be patient with your first post.
To unsubscribe from this group, send email to
clojure+u...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups "Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clojure+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jonah Benton

unread,
Feb 16, 2016, 10:39:37 AM2/16/16
to clo...@googlegroups.com
Hey Nick, tools.cli is great for interpretation of command line arguments to a program; to actually provide a user with your own limited-functionality shell, take a look at wrapping JLine:

Good luck,

Jonah

Jason Felice

unread,
Feb 16, 2016, 11:28:58 AM2/16/16
to clo...@googlegroups.com
Here are some thoughts from having done similar things:

1. Don't invent a syntax, as we already have lisp.  If the parens intimidate people, just inserting the outermost set for each line will get you a long way.  e.g.

(clojure.edn/read-string (str "(" line ")"))

2. Make a multimethod to dispatch the first element of the list.  (Not eval, or apply, since security is a concern.)  If you want nested expressions, a simple evaluator does essentially this, except evaluates arguments first.

With a little finess, you could instead allow only public symbols from a specific namespace in the first position, and call those functions in a secure way.

3. JLine is the command-line editing library that's like readline for Java.




Reply all
Reply to author
Forward
0 new messages