From 8757b8af44633d2cfb0ac4067402ce2e29dea21a Mon Sep 17 00:00:00 2001 From: Chip Senkbeil Date: Sat, 9 Oct 2021 21:58:54 -0500 Subject: [PATCH] Add distant_bin and distant_args to LaunchOpts --- distant-lua/src/session.rs | 5 ++++- distant-lua/src/session/opts.rs | 29 +++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/distant-lua/src/session.rs b/distant-lua/src/session.rs index 3527b94..5320bdf 100644 --- a/distant-lua/src/session.rs +++ b/distant-lua/src/session.rs @@ -160,6 +160,8 @@ impl Session { handler, ssh, timeout, + distant_bin, + distant_args, } = opts; // First, establish a connection to an SSH server @@ -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()?, diff --git a/distant-lua/src/session/opts.rs b/distant-lua/src/session/opts.rs index 667f677..3600cd8 100644 --- a/distant-lua/src/session/opts.rs +++ b/distant-lua/src/session/opts.rs @@ -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<'_> { @@ -171,6 +186,20 @@ impl<'lua> FromLua<'lua> for LaunchOpts<'lua> { let milliseconds: Option = tbl.get("timeout")?; Duration::from_millis(milliseconds.unwrap_or(TIMEOUT_MILLIS)) }, + distant_bin: { + let distant_bin: Option = 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 = lua.from_value(x)?; + args.join(" ") + } + } + }, }), LuaValue::Nil => Err(LuaError::FromLuaConversionError { from: "Nil",