#[derive(Debug, Clone)]
#[non_exhaustive]
pub struct SpawnOpts {
pub program: String,
pub socket: Option<String>,
pub session: Option<String>,
}
impl Default for SpawnOpts {
fn default() -> Self {
Self {
program: "tmux".to_string(),
socket: None,
session: None,
}
}
}
impl SpawnOpts {
pub fn new() -> Self {
Self::default()
}
pub fn program(mut self, program: impl Into<String>) -> Self {
self.program = program.into();
self
}
pub fn socket(mut self, socket: impl Into<String>) -> Self {
self.socket = Some(socket.into());
self
}
pub fn session(mut self, session: impl Into<String>) -> Self {
self.session = Some(session.into());
self
}
pub fn argv(&self) -> Vec<String> {
let mut argv = Vec::new();
if let Some(socket) = &self.socket {
argv.push("-L".to_string());
argv.push(socket.clone());
}
argv.push("-C".to_string());
argv.push("new-session".to_string());
argv.push("-A".to_string());
if let Some(session) = &self.session {
argv.push("-s".to_string());
argv.push(session.clone());
}
argv
}
}