mirror of
https://gitlab.com/vindarel/ciel.git
synced 2026-01-30 04:11:24 -08:00
scripts: use :flag, not :counter, and fix running files
This commit is contained in:
parent
d6588d08cd
commit
2c93b1576c
3 changed files with 17 additions and 13 deletions
|
|
@ -13,7 +13,7 @@ $ ciel script.lisp
|
|||
Call built-in scripts:
|
||||
|
||||
```
|
||||
$ ciel --script simpleHTTPserver 9000
|
||||
$ ciel -s simpleHTTPserver 9000
|
||||
```
|
||||
|
||||
An example script:
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@
|
|||
"Wrap this user code to handle common conditions, such as a C-c C-c to quit gracefully."
|
||||
;; But is it enough when we run a shell command?
|
||||
`(handler-case
|
||||
,s ;; --eval takes one form only.
|
||||
,s ;; --eval takes one form only so no need of ,@
|
||||
(sb-sys:interactive-interrupt (c)
|
||||
(declare (ignore c))
|
||||
(format! *error-output* "Bye!~%"))
|
||||
|
|
@ -113,7 +113,7 @@
|
|||
:long-name "script"
|
||||
:key :script)
|
||||
(clingon:make-option
|
||||
:counter
|
||||
:flag
|
||||
:description "list available scripts."
|
||||
:long-name "scripts"
|
||||
:short-name #\z
|
||||
|
|
@ -192,27 +192,24 @@
|
|||
(format! t "An error occured: ~a~&" c)))
|
||||
|
||||
(return-from top-level/handler))
|
||||
|
||||
;;
|
||||
;; --script / -s : run scripts by name.
|
||||
;;
|
||||
;; They are registered by name in the binary.
|
||||
;; Ideas:
|
||||
;; - look for scripts in specified directories.
|
||||
|
||||
(script-name
|
||||
;; ditch the "-s" option, must not be seen by the script.
|
||||
(pop uiop:*command-line-arguments*)
|
||||
(let ((dir (uiop:getcwd)))
|
||||
(uiop:with-current-directory (dir)
|
||||
(run-script script-name)))
|
||||
(run-script script-name)))
|
||||
(return-from top-level/handler))
|
||||
|
||||
;;
|
||||
;; list available scripts (helper command)
|
||||
;; --scripts : list available scripts (helper command).
|
||||
;;
|
||||
;; There's maybe a bug in Clingon:
|
||||
;; if this option is handled before -s, it is always caught.
|
||||
;; Because --scripts starts with --script?
|
||||
(scripts
|
||||
(format t "CIEL v~a~%~%" *ciel-version*)
|
||||
(format t "Available scripts:~&")
|
||||
|
|
@ -222,7 +219,10 @@
|
|||
(format! t "~%See: https://ciel-lang.github.io/CIEL/#/scripting~&")
|
||||
(return-from top-level/handler))
|
||||
|
||||
;; A free arg should denote a file.
|
||||
;;
|
||||
;; Free args: run (LOAD) a file.
|
||||
;;
|
||||
;; First, check the file exists.
|
||||
((and args
|
||||
(not (uiop:file-exists-p (first args))))
|
||||
(format t "file ~S does not exist.~&" (first args))
|
||||
|
|
|
|||
10
src/scripts/simpleHTTPserver.lisp
Normal file → Executable file
10
src/scripts/simpleHTTPserver.lisp
Normal file → Executable file
|
|
@ -2,7 +2,10 @@
|
|||
;;; Run with:
|
||||
;;; $ ciel -s simpleHTTPserver 4242
|
||||
;;;
|
||||
;;; or add a shebang line and make this script executable.
|
||||
;;; or add a shebang line and make this script executable:
|
||||
;; #!/usr/bin/env ciel
|
||||
;; =>
|
||||
;; $ ./simpleHTTPserver.lisp
|
||||
;;;
|
||||
|
||||
(in-package :ciel-user)
|
||||
|
|
@ -32,8 +35,9 @@
|
|||
(file-namestring path)
|
||||
;; How to simply get the directory name, not full path?
|
||||
;; pathname-directory -> (:relative "path" "to" "dir")
|
||||
(str:ensure-ends-with "/"
|
||||
(first (last (pathname-directory path))))))
|
||||
;; TODO: this is not yet merged in cl-str, sorry.
|
||||
(str:ensure-end "/"
|
||||
(first (last (pathname-directory path))))))
|
||||
|
||||
(defun show-file-list (file-list &key title)
|
||||
(with-page (:title title)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue