From 2c93b1576c034a296ec303097b36304d8165dfaa Mon Sep 17 00:00:00 2001 From: vindarel Date: Wed, 8 Mar 2023 16:49:45 +0100 Subject: [PATCH] scripts: use :flag, not :counter, and fix running files --- docs/scripting.md | 2 +- scripting.lisp | 18 +++++++++--------- src/scripts/simpleHTTPserver.lisp | 10 +++++++--- 3 files changed, 17 insertions(+), 13 deletions(-) mode change 100644 => 100755 src/scripts/simpleHTTPserver.lisp diff --git a/docs/scripting.md b/docs/scripting.md index fb6217f..e6bcddf 100644 --- a/docs/scripting.md +++ b/docs/scripting.md @@ -13,7 +13,7 @@ $ ciel script.lisp Call built-in scripts: ``` -$ ciel --script simpleHTTPserver 9000 +$ ciel -s simpleHTTPserver 9000 ``` An example script: diff --git a/scripting.lisp b/scripting.lisp index 108c245..af6a6db 100644 --- a/scripting.lisp +++ b/scripting.lisp @@ -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)) diff --git a/src/scripts/simpleHTTPserver.lisp b/src/scripts/simpleHTTPserver.lisp old mode 100644 new mode 100755 index e15386c..470e188 --- a/src/scripts/simpleHTTPserver.lisp +++ b/src/scripts/simpleHTTPserver.lisp @@ -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)