summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorArtyom V. Poptsov <poptsov.artyom@gmail.com>2015-07-26 21:39:49 +0300
committerArtyom V. Poptsov <poptsov.artyom@gmail.com>2015-07-26 21:39:49 +0300
commit49edea2db7f4c93019bd2926aa47966d7a23dfdc (patch)
tree639c0afec2fdd2f826186b405fba163183140911 /examples
parentmodules/ssh/dist/node.scm: Organize procedures, add comments (diff)
downloadguile-ssh-49edea2db7f4c93019bd2926aa47966d7a23dfdc.tar.gz
examples/rrepl.scm.in: Add to the repository
* examples/rrepl.scm.in: Add to the repository. * examples/Makefile.am (EXTRA_DIST): Add 'rrepl.scm.in'. (dist_examples_DATA, CLEANFILES): Add 'rrepl.scm'. * examples/README: Update.
Diffstat (limited to 'examples')
-rw-r--r--examples/Makefile.am8
-rw-r--r--examples/README5
-rw-r--r--examples/rrepl.scm.in84
3 files changed, 92 insertions, 5 deletions
diff --git a/examples/Makefile.am b/examples/Makefile.am
index 88ffb18..ed49ffa 100644
--- a/examples/Makefile.am
+++ b/examples/Makefile.am
@@ -20,11 +20,12 @@ EXTRA_DIST = \
sssh.scm.in \
ssshd.scm.in \
echo/server.scm.in \
- echo/client.scm.in
+ echo/client.scm.in \
+ rrepl.scm.in
examplesdir = $(pkgdatadir)/examples
examples_echodir = $(pkgdatadir)/examples/echo
-dist_examples_DATA = README sssh.scm ssshd.scm
+dist_examples_DATA = README sssh.scm ssshd.scm rrepl.scm
dist_examples_echo_DATA = echo/server.scm echo/client.scm
substitute = sed -e 's,[@]GUILE[@],$(GUILE),g'
@@ -38,4 +39,5 @@ SUFFIXES = .in
CLEANFILES = \
sssh.scm ssshd.scm \
- echo/server.scm echo/client.scm
+ echo/server.scm echo/client.scm \
+ rrepl.scm
diff --git a/examples/README b/examples/README
index f268f64..49e3242 100644
--- a/examples/README
+++ b/examples/README
@@ -37,5 +37,6 @@ Implementation of an SSH based echo protocol ([[https://tools.ietf.org/html/rfc8
Please find sources in =echo/= directory:
- echo/client.scm
- echo/server.scm
-
-
+* RREPL
+ A demo program that allows to connect to a remote REPL (RREPL) server. Pass
+ =--help= (or =-h=) flag to the program to get usage information.
diff --git a/examples/rrepl.scm.in b/examples/rrepl.scm.in
new file mode 100644
index 0000000..9f72ba2
--- /dev/null
+++ b/examples/rrepl.scm.in
@@ -0,0 +1,84 @@
+#!@GUILE@ \
+--debug -e main
+!#
+
+;;; rrepl.scm -- An example of RREPL usage.
+
+;; Copyright (C) 2015 Artyom V. Poptsov <poptsov.artyom@gmail.com>
+;;
+;; This program is free software: you can redistribute it and/or
+;; modify it under the terms of the GNU General Public License as
+;; published by the Free Software Foundation, either version 3 of the
+;; License, or (at your option) any later version.
+;;
+;; This program is distributed in the hope that it will be useful, but
+;; WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+;; General Public License for more details.
+;;
+;; You should have received a copy of the GNU General Public License
+;; along with this program. If not, see
+;; <http://www.gnu.org/licenses/>.
+
+
+;;; Commentary:
+
+;; A demo program that connects to a remote REPL (RREPL).
+
+
+;;; Code:
+
+(use-modules (ice-9 getopt-long)
+ (ssh session)
+ (ssh auth)
+ (ssh dist)
+ (ssh dist node))
+
+(define (print-help-and-exit)
+ "Print information about program usage."
+ (display "\
+Usage: rrepl.scm [options] <host>
+
+Connect to a remote REPL (RREPL). You can disconnect from a remote REPL by
+typing ',rq' into the REPL.
+
+Options:
+ --user, -u <user> User name.
+ --port, -p <port> SSH port number (default: 22)
+ --repl-port, -P <port> Gulie REPL port number (default: 37146)
+ --help, -h Print this message and exit.
+")
+ (exit))
+
+
+;;; Entry point
+
+(define (main args)
+ "Entry point of the program."
+ (let* ((options-spec '((user (single-char #\u) (value #t))
+ (port (single-char #\p) (value #t))
+ (repl-port (single-char #\P) (value #t))
+ (help (single-char #\h) (value #f))))
+ (options (getopt-long args options-spec))
+ (user (option-ref options 'user (getenv "USER")))
+ (port (option-ref options 'port "22"))
+ (repl-port (option-ref options 'repl-port "37146"))
+ (help-needed? (option-ref options 'help #f))
+ (args (option-ref options '() #f)))
+
+ (and (or help-needed?
+ (not args)
+ (null? args))
+ (print-help-and-exit))
+
+ (let* ((host (car args))
+ (s (make-session #:user user
+ #:host host
+ #:port (string->number port)
+ #:log-verbosity 'nolog)))
+ (connect! s)
+ (userauth-agent! s)
+ (rrepl (make-node s (string->number repl-port)))
+ (exit 0))))
+
+;;; rrepl.scm ends here.