Skip to content

Commit

Permalink
Raise an error when 'exec' is used with non-ros commands.
Browse files Browse the repository at this point in the history
  • Loading branch information
fukamachi committed Nov 11, 2023
1 parent 3b99a86 commit d303ae1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
8 changes: 7 additions & 1 deletion cli.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
(:import-from #:qlot/utils/cli
#:exec
#:which
#:command-line-arguments)
#:command-line-arguments
#:ros-script-p)
(:import-from #:qlot/utils
#:starts-with
#:generate-random-string)
Expand Down Expand Up @@ -380,6 +381,11 @@ OPTIONS:

(let ((command (or (which (first argv))
(first argv))))
(unless (or (member (file-namestring command)
'("ros")
:test 'equal)
(ros-script-p command))
(qlot/errors:ros-command-error "exec must be followed by 'ros' or a Roswell script"))
(exec (cons command (rest argv)))))
((equal "add" $1)
(unless argv
Expand Down
12 changes: 11 additions & 1 deletion utils/cli.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
(:use #:cl)
(:export #:exec
#:which
#:command-line-arguments))
#:command-line-arguments
#:ros-script-p))
(in-package #:qlot/utils/cli)

(defun command-line-arguments ()
Expand Down Expand Up @@ -55,3 +56,12 @@
:output s)))
(uiop/run-program:subprocess-error ()
nil)))

(defun ros-script-p (file)
(and (uiop:file-exists-p file)
(ignore-errors
(with-open-file (in file
:direction :input
:element-type 'character)
(and (equal (read-line in) "#!/bin/sh")
(equal (read-line in) "#|-*- mode:lisp -*-|#"))))))

0 comments on commit d303ae1

Please sign in to comment.