Skip to content

Commit 7b7c910

Browse files
committed
ScalaSshShell() now also takes a list of bindings
1 parent 5aa60ad commit 7b7c910

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

README

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@ Embed this in your code by running the following:
99

1010
val sshd = new ScalaSshShell(port=4444, name="test", user="user",
1111
passwd="fluke",
12-
keysResourcePath=Some("/test.ssh.keys"))
12+
keysResourcePath=Some("/test.ssh.keys"),
13+
IndexedSeq(
14+
("pi", "Double", 3.1415926),
15+
("nums", "IndexedSeq[Int]",
16+
Vector(1,2,3,4,5))))
1317

1418
Most of that should be self explanatory. The 'name' is the name that
1519
will be used for the parent thread, as well as the name that will
@@ -45,7 +49,9 @@ password:
4549
Welcome to Scala version 2.9.1.r0-b20110831114755 (Java HotSpot(TM) 64-Bit Server VM, Java 1.7.0).
4650
Type in expressions to have them evaluated.
4751
Type :help for more information.
48-
test> 1 to 10 sum
49-
res0: Int = 55
52+
test> nums.sum
53+
res0: Int = 15
54+
test> pi/2
55+
res1: Double = 1.5707963
5056
test> println("Hello World!")
5157
Hello World!

src/main/scala/ScalaSshShell.scala

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ import org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider
2424

2525
class ScalaSshShell(port: Int, name:
2626
String, user: String, passwd: String,
27-
keysResourcePath: Option[String]) {
27+
keysResourcePath: Option[String],
28+
bindings: Seq[(String, String, Any)]) {
2829
val sshd = org.apache.sshd.SshServer.setUpDefaultServer()
2930
sshd.setPort(port)
3031
sshd.setReuseAddress(true)
@@ -144,6 +145,8 @@ class ScalaSshShell(port: Int, name:
144145
il.intp.initialize()
145146
il.intp.beQuietDuring {
146147
il.intp.bind("stdout", pw)
148+
for ((bname, btype, bval) <- bindings)
149+
il.bind(bname, btype, bval)
147150
}
148151
il.intp.quietRun(
149152
"""def println(a: Any) = {
@@ -178,7 +181,11 @@ object ScalaSshShell {
178181
def main(args: Array[String]) {
179182
val sshd = new ScalaSshShell(port=4444, name="test", user="user",
180183
passwd="fluke",
181-
keysResourcePath=Some("/test.ssh.keys"))
184+
keysResourcePath=Some("/test.ssh.keys"),
185+
IndexedSeq(
186+
("pi", "Double", 3.1415926),
187+
("nums", "IndexedSeq[Int]",
188+
Vector(1,2,3,4,5))))
182189
}
183190

184191
def generateKeys(path: String) {

0 commit comments

Comments
 (0)