From 03083437944b825687f321cc698d07e75ca78359 Mon Sep 17 00:00:00 2001 From: Chip Senkbeil Date: Fri, 4 Feb 2022 23:22:09 -0600 Subject: [PATCH] Rename detached to persist (#94) --- CHANGELOG.md | 1 + distant-core/src/client/lsp/mod.rs | 4 +-- distant-core/src/client/process.rs | 4 +-- distant-core/src/client/session/ext.rs | 12 ++++----- distant-core/src/data.rs | 8 +++--- distant-core/src/server/distant/handler.rs | 30 +++++++++++----------- distant-core/src/server/distant/state.rs | 6 ++--- distant-lua/src/session/api.rs | 12 ++++----- distant-ssh2/src/handler.rs | 12 ++++----- distant-ssh2/tests/ssh2/session.rs | 20 +++++++-------- src/opt.rs | 8 +++--- src/subcommand/action.rs | 4 +-- src/subcommand/lsp.rs | 2 +- src/subcommand/shell.rs | 2 +- tests/cli/action/proc_spawn.rs | 10 ++++---- 15 files changed, 68 insertions(+), 67 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index db710dd..d192316 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Update ProcStdin, ProcStdout, and ProcStderr to use list of bytes instead of a string as a parameter; RemoteProcess and RemoteLspProcess now support reading and writing using either `String` or `Vec` +- Rename `--detached` and associated to `--persist` ### Removed - Github actions no longer use paths-filter so every PR & commit will test diff --git a/distant-core/src/client/lsp/mod.rs b/distant-core/src/client/lsp/mod.rs index 7b7bfc8..35b1e71 100644 --- a/distant-core/src/client/lsp/mod.rs +++ b/distant-core/src/client/lsp/mod.rs @@ -30,10 +30,10 @@ impl RemoteLspProcess { channel: SessionChannel, cmd: impl Into, args: Vec, - detached: bool, + persist: bool, pty: Option, ) -> Result { - let mut inner = RemoteProcess::spawn(tenant, channel, cmd, args, detached, pty).await?; + let mut inner = RemoteProcess::spawn(tenant, channel, cmd, args, persist, pty).await?; let stdin = inner.stdin.take().map(RemoteLspStdin::new); let stdout = inner.stdout.take().map(RemoteLspStdout::new); let stderr = inner.stderr.take().map(RemoteLspStderr::new); diff --git a/distant-core/src/client/process.rs b/distant-core/src/client/process.rs index 7fc6b36..2835020 100644 --- a/distant-core/src/client/process.rs +++ b/distant-core/src/client/process.rs @@ -81,7 +81,7 @@ impl RemoteProcess { mut channel: SessionChannel, cmd: impl Into, args: Vec, - detached: bool, + persist: bool, pty: Option, ) -> Result { let tenant = tenant.into(); @@ -94,7 +94,7 @@ impl RemoteProcess { vec![RequestData::ProcSpawn { cmd, args, - detached, + persist, pty, }], )) diff --git a/distant-core/src/client/session/ext.rs b/distant-core/src/client/session/ext.rs index 8eca6c5..ad3e90c 100644 --- a/distant-core/src/client/session/ext.rs +++ b/distant-core/src/client/session/ext.rs @@ -124,7 +124,7 @@ pub trait SessionChannelExt { tenant: impl Into, cmd: impl Into, args: Vec>, - detached: bool, + persist: bool, pty: Option, ) -> AsyncReturn<'_, RemoteProcess, RemoteProcessError>; @@ -134,7 +134,7 @@ pub trait SessionChannelExt { tenant: impl Into, cmd: impl Into, args: Vec>, - detached: bool, + persist: bool, pty: Option, ) -> AsyncReturn<'_, RemoteLspProcess, RemoteProcessError>; @@ -379,14 +379,14 @@ impl SessionChannelExt for SessionChannel { tenant: impl Into, cmd: impl Into, args: Vec>, - detached: bool, + persist: bool, pty: Option, ) -> AsyncReturn<'_, RemoteProcess, RemoteProcessError> { let tenant = tenant.into(); let cmd = cmd.into(); let args = args.into_iter().map(Into::into).collect(); Box::pin(async move { - RemoteProcess::spawn(tenant, self.clone(), cmd, args, detached, pty).await + RemoteProcess::spawn(tenant, self.clone(), cmd, args, persist, pty).await }) } @@ -395,14 +395,14 @@ impl SessionChannelExt for SessionChannel { tenant: impl Into, cmd: impl Into, args: Vec>, - detached: bool, + persist: bool, pty: Option, ) -> AsyncReturn<'_, RemoteLspProcess, RemoteProcessError> { let tenant = tenant.into(); let cmd = cmd.into(); let args = args.into_iter().map(Into::into).collect(); Box::pin(async move { - RemoteLspProcess::spawn(tenant, self.clone(), cmd, args, detached, pty).await + RemoteLspProcess::spawn(tenant, self.clone(), cmd, args, persist, pty).await }) } diff --git a/distant-core/src/data.rs b/distant-core/src/data.rs index 80f4bba..34572d4 100644 --- a/distant-core/src/data.rs +++ b/distant-core/src/data.rs @@ -219,10 +219,10 @@ pub enum RequestData { /// Arguments for the command args: Vec, - /// Whether or not the process should be detached, meaning that the process will not be + /// Whether or not the process should be persistent, meaning that the process will not be /// killed when the associated client disconnects #[cfg_attr(feature = "structopt", structopt(long))] - detached: bool, + persist: bool, /// If provided, will spawn process in a pty, otherwise spawns directly #[cfg_attr(feature = "structopt", structopt(long))] @@ -617,8 +617,8 @@ pub struct RunningProcess { /// Arguments for the command pub args: Vec, - /// Whether or not the process was run in detached mode - pub detached: bool, + /// Whether or not the process was run in persist mode + pub persist: bool, /// Pty associated with running process if it has one pub pty: Option, diff --git a/distant-core/src/server/distant/handler.rs b/distant-core/src/server/distant/handler.rs index 6f5b4db..fc2cb8a 100644 --- a/distant-core/src/server/distant/handler.rs +++ b/distant-core/src/server/distant/handler.rs @@ -101,9 +101,9 @@ pub(super) async fn process( RequestData::ProcSpawn { cmd, args, - detached, + persist, pty, - } => proc_spawn(conn_id, state, reply, cmd, args, detached, pty).await, + } => proc_spawn(conn_id, state, reply, cmd, args, persist, pty).await, RequestData::ProcKill { id } => proc_kill(conn_id, state, id).await, RequestData::ProcStdin { id, data } => proc_stdin(conn_id, state, id, data).await, RequestData::ProcResizePty { id, size } => { @@ -433,7 +433,7 @@ async fn proc_spawn( reply: F, cmd: String, args: Vec, - detached: bool, + persist: bool, pty: Option, ) -> Result where @@ -544,7 +544,7 @@ where ProcessState { cmd, args, - detached, + persist, id, stdin, killer, @@ -632,7 +632,7 @@ async fn proc_list(state: HState) -> Result { .map(|p| RunningProcess { cmd: p.cmd.to_string(), args: p.args.clone(), - detached: p.detached, + persist: p.persist, // TODO: Support retrieving current pty size pty: None, id: p.id, @@ -2143,7 +2143,7 @@ mod tests { vec![RequestData::ProcSpawn { cmd: DOES_NOT_EXIST_BIN.to_str().unwrap().to_string(), args: Vec::new(), - detached: false, + persist: false, pty: None, }], ); @@ -2170,7 +2170,7 @@ mod tests { vec![RequestData::ProcSpawn { cmd: SCRIPT_RUNNER.to_string(), args: vec![ECHO_ARGS_TO_STDOUT_SH.to_str().unwrap().to_string()], - detached: false, + persist: false, pty: None, }], ); @@ -2204,7 +2204,7 @@ mod tests { ECHO_ARGS_TO_STDOUT_SH.to_str().unwrap().to_string(), String::from("some stdout"), ], - detached: false, + persist: false, pty: None, }], ); @@ -2271,7 +2271,7 @@ mod tests { ECHO_ARGS_TO_STDERR_SH.to_str().unwrap().to_string(), String::from("some stderr"), ], - detached: false, + persist: false, pty: None, }], ); @@ -2335,7 +2335,7 @@ mod tests { vec![RequestData::ProcSpawn { cmd: SCRIPT_RUNNER.to_string(), args: vec![SLEEP_SH.to_str().unwrap().to_string(), String::from("0.1")], - detached: false, + persist: false, pty: None, }], ); @@ -2379,7 +2379,7 @@ mod tests { vec![RequestData::ProcSpawn { cmd: SCRIPT_RUNNER.to_string(), args: vec![SLEEP_SH.to_str().unwrap().to_string(), String::from("1")], - detached: false, + persist: false, pty: None, }], ); @@ -2455,7 +2455,7 @@ mod tests { vec![RequestData::ProcSpawn { cmd: SCRIPT_RUNNER.to_string(), args: vec![SLEEP_SH.to_str().unwrap().to_string(), String::from("1")], - detached: false, + persist: false, pty: None, }], ); @@ -2552,7 +2552,7 @@ mod tests { vec![RequestData::ProcSpawn { cmd: SCRIPT_RUNNER.to_string(), args: vec![ECHO_STDIN_TO_STDOUT_SH.to_str().unwrap().to_string()], - detached: false, + persist: false, pty: None, }], ); @@ -2626,7 +2626,7 @@ mod tests { RequestData::ProcSpawn { cmd: SCRIPT_RUNNER.to_string(), args: vec![SLEEP_SH.to_str().unwrap().to_string(), String::from("1")], - detached: false, + persist: false, pty: None, }, RequestData::ProcList {}, @@ -2651,7 +2651,7 @@ mod tests { entries: vec![RunningProcess { cmd: SCRIPT_RUNNER.to_string(), args: vec![SLEEP_SH.to_str().unwrap().to_string(), String::from("1")], - detached: false, + persist: false, pty: None, id, }], diff --git a/distant-core/src/server/distant/state.rs b/distant-core/src/server/distant/state.rs index 821e6b3..53e2c9a 100644 --- a/distant-core/src/server/distant/state.rs +++ b/distant-core/src/server/distant/state.rs @@ -16,7 +16,7 @@ pub struct State { pub struct ProcessState { pub cmd: String, pub args: Vec, - pub detached: bool, + pub persist: bool, pub id: usize, pub stdin: Option>, @@ -68,7 +68,7 @@ impl State { if let Some(ids) = self.client_processes.remove(&conn_id) { for id in ids { if let Some(mut process) = self.processes.remove(&id) { - if !process.detached { + if !process.persist { trace!( " Requesting proc {} be killed", conn_id, @@ -83,7 +83,7 @@ impl State { } } else { trace!( - " Proc {} is detached and will not be killed", + " Proc {} is persistent and will not be killed", conn_id, process.id ); diff --git a/distant-lua/src/session/api.rs b/distant-lua/src/session/api.rs index d559616..45d76d4 100644 --- a/distant-lua/src/session/api.rs +++ b/distant-lua/src/session/api.rs @@ -164,22 +164,22 @@ make_api!( make_api!( spawn, RemoteProcess, - { cmd: String, #[serde(default)] args: Vec, #[serde(default)] pty: Option, #[serde(default)] detached: bool }, + { cmd: String, #[serde(default)] args: Vec, #[serde(default)] pty: Option, #[serde(default)] persist: bool }, |channel, tenant, params| { - channel.spawn(tenant, params.cmd, params.args, params.detached, params.pty).await + channel.spawn(tenant, params.cmd, params.args, params.persist, params.pty).await } ); make_api!( spawn_wait, Output, - { cmd: String, #[serde(default)] args: Vec, #[serde(default)] pty: Option, #[serde(default)] detached: bool }, + { cmd: String, #[serde(default)] args: Vec, #[serde(default)] pty: Option, #[serde(default)] persist: bool }, |channel, tenant, params| { let proc = channel.spawn( tenant, params.cmd, params.args, - params.detached, + params.persist, params.pty, ).await.to_lua_err()?; let id = LuaRemoteProcess::from_distant_async(proc).await?.id; @@ -190,9 +190,9 @@ make_api!( make_api!( spawn_lsp, RemoteLspProcess, - { cmd: String, #[serde(default)] args: Vec, #[serde(default)] pty: Option, #[serde(default)] detached: bool }, + { cmd: String, #[serde(default)] args: Vec, #[serde(default)] pty: Option, #[serde(default)] persist: bool }, |channel, tenant, params| { - channel.spawn_lsp(tenant, params.cmd, params.args, params.detached, params.pty).await + channel.spawn_lsp(tenant, params.cmd, params.args, params.persist, params.pty).await } ); diff --git a/distant-ssh2/src/handler.rs b/distant-ssh2/src/handler.rs index ade7b16..72220a1 100644 --- a/distant-ssh2/src/handler.rs +++ b/distant-ssh2/src/handler.rs @@ -35,7 +35,7 @@ struct Process { id: usize, cmd: String, args: Vec, - detached: bool, + persist: bool, stdin_tx: mpsc::Sender>, kill_tx: mpsc::Sender<()>, resize_tx: mpsc::Sender, @@ -97,9 +97,9 @@ pub(super) async fn process( RequestData::ProcSpawn { cmd, args, - detached, + persist, pty, - } => proc_spawn(session, state, cmd, args, detached, pty).await, + } => proc_spawn(session, state, cmd, args, persist, pty).await, RequestData::ProcResizePty { id, size } => { proc_resize_pty(session, state, id, size).await } @@ -614,7 +614,7 @@ async fn proc_spawn( state: Arc>, cmd: String, args: Vec, - detached: bool, + persist: bool, pty: Option, ) -> io::Result { let cmd_string = format!("{} {}", cmd, args.join(" ")); @@ -642,7 +642,7 @@ async fn proc_spawn( id, cmd, args, - detached, + persist, stdin_tx: stdin, kill_tx: killer, resize_tx: resizer, @@ -722,7 +722,7 @@ async fn proc_list(_session: WezSession, state: Arc>) -> io::Result .map(|p| RunningProcess { cmd: p.cmd.to_string(), args: p.args.clone(), - detached: p.detached, + persist: p.persist, // TODO: Support pty size from ssh pty: None, id: p.id, diff --git a/distant-ssh2/tests/ssh2/session.rs b/distant-ssh2/tests/ssh2/session.rs index 92ecdf9..9b1f048 100644 --- a/distant-ssh2/tests/ssh2/session.rs +++ b/distant-ssh2/tests/ssh2/session.rs @@ -1355,7 +1355,7 @@ async fn proc_spawn_should_send_error_over_stderr_on_failure(#[future] session: vec![RequestData::ProcSpawn { cmd: DOES_NOT_EXIST_BIN.to_str().unwrap().to_string(), args: Vec::new(), - detached: false, + persist: false, pty: None, }], ); @@ -1402,7 +1402,7 @@ async fn proc_spawn_should_send_back_proc_start_on_success(#[future] session: Se vec![RequestData::ProcSpawn { cmd: SCRIPT_RUNNER.to_string(), args: vec![ECHO_ARGS_TO_STDOUT_SH.to_str().unwrap().to_string()], - detached: false, + persist: false, pty: None, }], ); @@ -1434,7 +1434,7 @@ async fn proc_spawn_should_send_back_stdout_periodically_when_available( ECHO_ARGS_TO_STDOUT_SH.to_str().unwrap().to_string(), String::from("'some stdout'"), ], - detached: false, + persist: false, pty: None, }], ); @@ -1501,7 +1501,7 @@ async fn proc_spawn_should_send_back_stderr_periodically_when_available( ECHO_ARGS_TO_STDERR_SH.to_str().unwrap().to_string(), String::from("'some stderr'"), ], - detached: false, + persist: false, pty: None, }], ); @@ -1563,7 +1563,7 @@ async fn proc_spawn_should_clear_process_from_state_when_done(#[future] session: vec![RequestData::ProcSpawn { cmd: SCRIPT_RUNNER.to_string(), args: vec![SLEEP_SH.to_str().unwrap().to_string(), String::from("0.1")], - detached: false, + persist: false, pty: None, }], ); @@ -1612,7 +1612,7 @@ async fn proc_spawn_should_clear_process_from_state_when_killed(#[future] sessio vec![RequestData::ProcSpawn { cmd: SCRIPT_RUNNER.to_string(), args: vec![SLEEP_SH.to_str().unwrap().to_string(), String::from("1")], - detached: false, + persist: false, pty: None, }], ); @@ -1687,7 +1687,7 @@ async fn proc_kill_should_send_ok_and_done_responses_on_success(#[future] sessio vec![RequestData::ProcSpawn { cmd: SCRIPT_RUNNER.to_string(), args: vec![SLEEP_SH.to_str().unwrap().to_string(), String::from("1")], - detached: false, + persist: false, pty: None, }], ); @@ -1763,7 +1763,7 @@ async fn proc_stdin_should_send_ok_on_success_and_properly_send_stdin_to_process vec![RequestData::ProcSpawn { cmd: SCRIPT_RUNNER.to_string(), args: vec![ECHO_STDIN_TO_STDOUT_SH.to_str().unwrap().to_string()], - detached: false, + persist: false, pty: None, }], ); @@ -1813,7 +1813,7 @@ async fn proc_list_should_send_proc_entry_list(#[future] session: Session) { vec![RequestData::ProcSpawn { cmd: SCRIPT_RUNNER.to_string(), args: vec![SLEEP_SH.to_str().unwrap().to_string(), String::from("10")], - detached: false, + persist: false, pty: None, }], ); @@ -1839,7 +1839,7 @@ async fn proc_list_should_send_proc_entry_list(#[future] session: Session) { entries: vec![RunningProcess { cmd: SCRIPT_RUNNER.to_string(), args: vec![SLEEP_SH.to_str().unwrap().to_string(), String::from("10")], - detached: false, + persist: false, pty: None, id, }], diff --git a/src/opt.rs b/src/opt.rs index 02cd9ce..3126627 100644 --- a/src/opt.rs +++ b/src/opt.rs @@ -677,10 +677,10 @@ pub struct LspSubcommand { #[structopt(flatten)] pub ssh_connection: SshConnectionOpts, - /// If provided, will run in detached mode, meaning that the process will not be killed if the + /// If provided, will run in persist mode, meaning that the process will not be killed if the /// client disconnects from the server #[structopt(long)] - pub detached: bool, + pub persist: bool, /// If provided, will run LSP in a pty #[structopt(long)] @@ -740,10 +740,10 @@ pub struct ShellSubcommand { #[structopt(flatten)] pub ssh_connection: SshConnectionOpts, - /// If provided, will run in detached mode, meaning that the process will not be killed if the + /// If provided, will run in persist mode, meaning that the process will not be killed if the /// client disconnects from the server #[structopt(long)] - pub detached: bool, + pub persist: bool, /// Command to run on the remote machine as the shell (defaults to $TERM) pub cmd: Option, diff --git a/src/subcommand/action.rs b/src/subcommand/action.rs index 4d82b56..72b7f6b 100644 --- a/src/subcommand/action.rs +++ b/src/subcommand/action.rs @@ -91,7 +91,7 @@ async fn start( Some(RequestData::ProcSpawn { cmd, args, - detached, + persist, pty, }), ) if is_shell_format => { @@ -100,7 +100,7 @@ async fn start( session.clone_channel(), cmd, args, - detached, + persist, pty, ) .await?; diff --git a/src/subcommand/lsp.rs b/src/subcommand/lsp.rs index cf8701b..b0edac0 100644 --- a/src/subcommand/lsp.rs +++ b/src/subcommand/lsp.rs @@ -74,7 +74,7 @@ async fn start( session.clone_channel(), cmd.cmd, cmd.args, - cmd.detached, + cmd.persist, if cmd.pty { terminal_size() .map(|(Width(width), Height(height))| PtySize::from_rows_and_cols(height, width)) diff --git a/src/subcommand/shell.rs b/src/subcommand/shell.rs index c5825d2..401014f 100644 --- a/src/subcommand/shell.rs +++ b/src/subcommand/shell.rs @@ -80,7 +80,7 @@ async fn start( session.clone_channel(), cmd.cmd.unwrap_or_else(|| "/bin/sh".to_string()), cmd.args, - cmd.detached, + cmd.persist, terminal_size().map(|(Width(cols), Height(rows))| PtySize::from_rows_and_cols(rows, cols)), ) .await?; diff --git a/tests/cli/action/proc_spawn.rs b/tests/cli/action/proc_spawn.rs index 7609206..2e6672b 100644 --- a/tests/cli/action/proc_spawn.rs +++ b/tests/cli/action/proc_spawn.rs @@ -171,7 +171,7 @@ fn should_support_json_to_execute_program_and_return_exit_status(mut action_cmd: payload: vec![RequestData::ProcSpawn { cmd: SCRIPT_RUNNER.to_string(), args: vec![ECHO_ARGS_TO_STDOUT_SH.to_str().unwrap().to_string()], - detached: false, + persist: false, pty: None, }], }; @@ -205,7 +205,7 @@ fn should_support_json_to_capture_and_print_stdout(ctx: &'_ DistantServerCtx) { ECHO_ARGS_TO_STDOUT_SH.to_str().unwrap().to_string(), output.to_string(), ], - detached: false, + persist: false, pty: None, }], }; @@ -275,7 +275,7 @@ fn should_support_json_to_capture_and_print_stderr(ctx: &'_ DistantServerCtx) { ECHO_ARGS_TO_STDERR_SH.to_str().unwrap().to_string(), output.to_string(), ], - detached: false, + persist: false, pty: None, }], }; @@ -341,7 +341,7 @@ fn should_support_json_to_forward_stdin_to_remote_process(ctx: &'_ DistantServer payload: vec![RequestData::ProcSpawn { cmd: SCRIPT_RUNNER.to_string(), args: vec![ECHO_STDIN_TO_STDOUT_SH.to_str().unwrap().to_string()], - detached: false, + persist: false, pty: None, }], }; @@ -436,7 +436,7 @@ fn should_support_json_output_for_error(mut action_cmd: Command) { payload: vec![RequestData::ProcSpawn { cmd: DOES_NOT_EXIST_BIN.to_str().unwrap().to_string(), args: Vec::new(), - detached: false, + persist: false, pty: None, }], };