Skip to content

Commit 3bdbfcd

Browse files
authored
Add specific argument types to connect_repl (#41)
This should make it a little easier to see what's going wrong if the wrong argument type is passed to ssh_opts or similar. Also specify clearer field types in the `Connection` struct.
1 parent ed52d42 commit 3bdbfcd

File tree

2 files changed

+26
-19
lines changed

2 files changed

+26
-19
lines changed

src/client.jl

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -107,20 +107,24 @@ end
107107
#-------------------------------------------------------------------------------
108108
# Client side connection / session handling
109109
mutable struct Connection
110-
host
111-
port
112-
tunnel
113-
ssh_opts
114-
region
115-
namespace
116-
socket
117-
in_module
110+
host::Union{AbstractString,Sockets.IPAddr}
111+
port::Int
112+
tunnel::Symbol
113+
ssh_opts::Cmd
114+
region::Union{AbstractString,Nothing}
115+
namespace::Union{AbstractString,Nothing}
116+
socket::Union{IO,Nothing}
117+
in_module::Symbol
118118
end
119119

120-
function Connection(; host=Sockets.localhost, port::Integer=DEFAULT_PORT,
121-
tunnel::Symbol = host!=Sockets.localhost ? :ssh : :none,
122-
ssh_opts=``, region=nothing, namespace=nothing)
123-
conn = Connection(host, port, tunnel, ssh_opts, region, namespace, nothing, :Main)
120+
function Connection(; host::Union{AbstractString,Sockets.IPAddr}=Sockets.localhost,
121+
port::Integer=DEFAULT_PORT,
122+
tunnel::Symbol=host!=Sockets.localhost ? :ssh : :none,
123+
ssh_opts::Cmd=``,
124+
region=nothing,
125+
namespace=nothing,
126+
in_module::Symbol=:Main)
127+
conn = Connection(host, port, tunnel, ssh_opts, region, namespace, nothing, in_module)
124128
setup_connection!(conn)
125129
finalizer(close, conn)
126130
end
@@ -417,10 +421,10 @@ that `host` needs to be running an ssh server and you need ssh credentials set
417421
up for use on that host. For secure networks this can be disabled by setting
418422
`tunnel=:none`.
419423
420-
To provide extra options to SSH, you may use the `ssh_opts` keyword, for
421-
example an identity file may be set with ```ssh_opts = `-i /path/to/identity.pem` ```.
422-
Alternatively, you may want to set this up permanently using a `Host` section
423-
in your ssh config file.
424+
To provide extra options to SSH, you may pass a `Cmd` object in the `ssh_opts`
425+
keyword, for example an identity file may be set with ```ssh_opts = `-i
426+
/path/to/identity.pem` ```. For a more permanent solution, add a `Host` section
427+
to your ssh config file.
424428
425429
You can also use the following technologies for tunneling in place of SSH:
426430
1) AWS Session Manager: set `tunnel=:aws`. The optional `region` keyword
@@ -432,8 +436,11 @@ See README.md for more information.
432436
"""
433437
function connect_repl(host=Sockets.localhost, port::Integer=DEFAULT_PORT;
434438
tunnel::Symbol = host!=Sockets.localhost ? :ssh : :none,
435-
ssh_opts=``, region=nothing, namespace=nothing,
436-
startup_text=true, repl=Base.active_repl)
439+
ssh_opts::Cmd=``,
440+
region::Union{AbstractString,Nothing}=nothing,
441+
namespace::Union{AbstractString,Nothing}=nothing,
442+
startup_text::Bool=true,
443+
repl=Base.active_repl)
437444
global _repl_client_connection
438445

439446
if !isnothing(_repl_client_connection)

test/runtests.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ end
5252
function fake_conn(host, port; is_open=true)
5353
io = IOBuffer()
5454
is_open || close(io)
55-
RemoteREPL.Connection(host, port, nothing, nothing, nothing, nothing, io, :Main)
55+
RemoteREPL.Connection(host, port, :none, ``, nothing, nothing, io, :Main)
5656
end
5757
@test repl_prompt_text(fake_conn(Sockets.localhost, DEFAULT_PORT)) == "julia@localhost> "
5858
@test repl_prompt_text(fake_conn("localhost", DEFAULT_PORT)) == "julia@localhost> "

0 commit comments

Comments
 (0)