a4d620f7b9cad5b2373eaebf28f5f24c2d078a06
[clnl] / src / main / clnl / extensions / cli / cli.lisp
1 ; Copyright 2022 Frank Duncan (frank@consxy.com) under AGPL3.  See distributed LICENSE.txt.
2 (in-package #:clnl-extension-cli)
3
4 (defmethod clnl-extensions:prims ((extension (eql :cli)))
5  (list
6   (list :name :q :type :command :func #'shut-down)
7   (list :name :load :type :command :args '(t) :func #'load-file)
8   (list :name :help :type :command :args '((:token :optional)) :precedence 20 :func #'help)
9   (list
10    :name :button :type :command :args '(:string (:number :optional))
11    :precedence 20 :func #'clnl-model:execute-button)))
12
13 (defun shut-down ()
14  (sb-ext:exit :abort t))
15
16 (defun load-file (file)
17  (clnl:boot file))
18
19 (defun help (&optional token)
20  (format t
21   (if (not token)
22    "Placeholder help facility, try <:help :q> or <:help :load> for information about the commands we accept"
23    (case token
24     (:|:Q| ":q quits out of clnl")
25     (:|:LOAD|
26      (concatenate 'string
27       ":load <filename> loads up a model into the current clnl instance."
28       " Try :load \"Wolf Sheep Predation.nlogo\""))
29     (t (format nil "Don't have help for ~S" token))))))