mirror of
https://github.com/hymkor/lispect.git
synced 2026-08-28 04:46:59 -04:00
example.lsp: block..return-from to catch..throw
This commit is contained in:
@@ -15,11 +15,11 @@ $ `lispect example.lsp USERNAME@DOMAIN PASSWORD`
|
|||||||
→ login `USERNAME@DOMAIN` with `ssh` and input `PASSWORD` automatically
|
→ login `USERNAME@DOMAIN` with `ssh` and input `PASSWORD` automatically
|
||||||
|
|
||||||
```example.lsp
|
```example.lsp
|
||||||
(block main
|
(catch 'fail
|
||||||
(if (< (length ARGV) 2)
|
(if (< (length ARGV) 2)
|
||||||
(progn
|
(progn
|
||||||
(format (error-output) "Usage: ~A ~A USERNAME@DOMAIN PASSWORD~%" EXECUTABLE-NAME PROGRAM-NAME)
|
(format (error-output) "Usage: ~A ~A USERNAME@DOMAIN PASSWORD~%" EXECUTABLE-NAME PROGRAM-NAME)
|
||||||
(return-from main nil)))
|
(throw 'fail nil)))
|
||||||
|
|
||||||
(let ((account (car ARGV))
|
(let ((account (car ARGV))
|
||||||
(password (cadr ARGV))
|
(password (cadr ARGV))
|
||||||
@@ -28,29 +28,29 @@ $ `lispect example.lsp USERNAME@DOMAIN PASSWORD`
|
|||||||
(with-handler
|
(with-handler
|
||||||
(lambda (c)
|
(lambda (c)
|
||||||
(format (error-output) "ssh is not found~%")
|
(format (error-output) "ssh is not found~%")
|
||||||
(return-from main nil))
|
(throw 'fail nil))
|
||||||
(setq sshpid (spawn "ssh" account)))
|
(setq sshpid (spawn "ssh" account)))
|
||||||
|
|
||||||
(expect*
|
(expect*
|
||||||
("[fingerprint])?"
|
("[fingerprint])?"
|
||||||
(sendln "yes")
|
(sendln "yes")
|
||||||
(expect "password: ")
|
(expect "password:")
|
||||||
(sendln password))
|
(sendln password))
|
||||||
("password: "
|
("password:"
|
||||||
(sendln password))
|
(sendln password))
|
||||||
(("Connection refused"
|
(("Connection refused"
|
||||||
"Could not resolve hostname")
|
"Could not resolve hostname")
|
||||||
(return-from main nil))
|
(throw 'fail nil))
|
||||||
(30
|
(30
|
||||||
(format (error-output) "TIME OUT~%")
|
(format (error-output) "TIME OUT~%")
|
||||||
(return-from main nil)))
|
(throw 'fail nil)))
|
||||||
|
|
||||||
(expect*
|
(expect*
|
||||||
("Permission denied"
|
("Permission denied"
|
||||||
(expect "password:")
|
(expect "password:")
|
||||||
(send #\U3)
|
(send #\U3)
|
||||||
(wait sshpid)
|
(wait sshpid)
|
||||||
(return-from main nil)
|
(throw 'fail nil)
|
||||||
)
|
)
|
||||||
("$ "))
|
("$ "))
|
||||||
(sendln "echo YOU CAN CALL SOME COMMAND HERE")
|
(sendln "echo YOU CAN CALL SOME COMMAND HERE")
|
||||||
@@ -118,7 +118,7 @@ Parameters enclosed in curly braces {...} are optional and can be omitted.
|
|||||||
- The path of the executable of lispect
|
- The path of the executable of lispect
|
||||||
- `MATCH`
|
- `MATCH`
|
||||||
- The matching string in the block of `(expect*)`
|
- The matching string in the block of `(expect*)`
|
||||||
- `(block NAME FORM...)` and `(return-from NAME RESULT-FORM)`
|
- `(catch TAG-FORM FORM...)` and `(throw TAG-FORM RESULT-FORM)`
|
||||||
- Non-local exits. See also [ISLISP draft - 14.7. Non-local exits](https://islisp-dev.github.io/ISLispHyperDraft/islisp-v23.html#non_local_exits)
|
- Non-local exits. See also [ISLISP draft - 14.7. Non-local exits](https://islisp-dev.github.io/ISLispHyperDraft/islisp-v23.html#non_local_exits)
|
||||||
- `(with-handler HANDLER FORM...)`
|
- `(with-handler HANDLER FORM...)`
|
||||||
- When an error occurs in `FORMS...`, call `HANDLER`.
|
- When an error occurs in `FORMS...`, call `HANDLER`.
|
||||||
|
|||||||
+6
-6
@@ -1,8 +1,8 @@
|
|||||||
(block main
|
(catch 'fail
|
||||||
(if (< (length ARGV) 2)
|
(if (< (length ARGV) 2)
|
||||||
(progn
|
(progn
|
||||||
(format (error-output) "Usage: ~A ~A USERNAME@DOMAIN PASSWORD~%" EXECUTABLE-NAME PROGRAM-NAME)
|
(format (error-output) "Usage: ~A ~A USERNAME@DOMAIN PASSWORD~%" EXECUTABLE-NAME PROGRAM-NAME)
|
||||||
(return-from main nil)))
|
(throw 'fail nil)))
|
||||||
|
|
||||||
(let ((account (car ARGV))
|
(let ((account (car ARGV))
|
||||||
(password (cadr ARGV))
|
(password (cadr ARGV))
|
||||||
@@ -11,7 +11,7 @@
|
|||||||
(with-handler
|
(with-handler
|
||||||
(lambda (c)
|
(lambda (c)
|
||||||
(format (error-output) "ssh is not found~%")
|
(format (error-output) "ssh is not found~%")
|
||||||
(return-from main nil))
|
(throw 'fail nil))
|
||||||
(setq sshpid (spawn "ssh" account)))
|
(setq sshpid (spawn "ssh" account)))
|
||||||
|
|
||||||
(expect*
|
(expect*
|
||||||
@@ -23,17 +23,17 @@
|
|||||||
(sendln password))
|
(sendln password))
|
||||||
(("Connection refused"
|
(("Connection refused"
|
||||||
"Could not resolve hostname")
|
"Could not resolve hostname")
|
||||||
(return-from main nil))
|
(throw 'fail nil))
|
||||||
(30
|
(30
|
||||||
(format (error-output) "TIME OUT~%")
|
(format (error-output) "TIME OUT~%")
|
||||||
(return-from main nil)))
|
(throw 'fail nil)))
|
||||||
|
|
||||||
(expect*
|
(expect*
|
||||||
("Permission denied"
|
("Permission denied"
|
||||||
(expect "password:")
|
(expect "password:")
|
||||||
(send #\U3)
|
(send #\U3)
|
||||||
(wait sshpid)
|
(wait sshpid)
|
||||||
(return-from main nil)
|
(throw 'fail nil)
|
||||||
)
|
)
|
||||||
("$ "))
|
("$ "))
|
||||||
(sendln "echo YOU CAN CALL SOME COMMAND HERE")
|
(sendln "echo YOU CAN CALL SOME COMMAND HERE")
|
||||||
|
|||||||
Reference in New Issue
Block a user