Skip to content

Commit

Permalink
Add distant_bin and distant_args to LaunchOpts
Browse files Browse the repository at this point in the history
  • Loading branch information
chipsenkbeil committed Oct 10, 2021
1 parent 2ae8095 commit 8757b8a
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
5 changes: 4 additions & 1 deletion distant-lua/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ impl Session {
handler,
ssh,
timeout,
distant_bin,
distant_args,
} = opts;

// First, establish a connection to an SSH server
Expand All @@ -175,8 +177,9 @@ impl Session {
let session = match mode {
Mode::Distant => ssh_session
.into_distant_session(IntoDistantSessionOpts {
binary: distant_bin,
args: distant_args,
timeout,
..Default::default()
})
.await
.to_lua_err()?,
Expand Down
29 changes: 29 additions & 0 deletions distant-lua/src/session/opts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,26 @@ impl<'lua> FromLua<'lua> for ConnectOpts {

#[derive(Default)]
pub struct LaunchOpts<'a> {
/// Host to connect to remotely (e.g. example.com)
pub host: String,

/// Mode to use for communication (ssh or distant server)
pub mode: Mode,

/// Callbacks to be triggered on various authentication events
pub handler: Ssh2AuthHandler<'a>,

/// Miscellaneous ssh configuration options
pub ssh: Ssh2SessionOpts,

/// Maximum time to wait for launch to complete
pub timeout: Duration,

/// Binary representing the distant server on the remote machine
pub distant_bin: String,

/// Additional CLI options to pass to the distant server when starting
pub distant_args: String,
}

impl fmt::Debug for LaunchOpts<'_> {
Expand Down Expand Up @@ -171,6 +186,20 @@ impl<'lua> FromLua<'lua> for LaunchOpts<'lua> {
let milliseconds: Option<u64> = tbl.get("timeout")?;
Duration::from_millis(milliseconds.unwrap_or(TIMEOUT_MILLIS))
},
distant_bin: {
let distant_bin: Option<String> = tbl.get("distant_bin")?;
distant_bin.unwrap_or_else(|| String::from("distant"))
},
distant_args: {
let value: LuaValue = tbl.get("distant_args")?;
match value {
LuaValue::String(args) => args.to_str()?.to_string(),
x => {
let args: Vec<String> = lua.from_value(x)?;
args.join(" ")
}
}
},
}),
LuaValue::Nil => Err(LuaError::FromLuaConversionError {
from: "Nil",
Expand Down

0 comments on commit 8757b8a

Please sign in to comment.