From ddfa832b7c13a5f8edb106373c61686f7ef2428e Mon Sep 17 00:00:00 2001 From: noam teyssier <22600644+noamteyssier@users.noreply.github.com> Date: Mon, 22 Jul 2024 11:57:03 -0700 Subject: [PATCH] feat: converted kill and delete session input to vector to delete or kill multiple sessions at once. Renamed variables in main and command to match plurality --- src/commands.rs | 42 ++++++++++++++++++++--------------------- src/main.rs | 8 ++++---- zellij-utils/src/cli.rs | 8 ++++---- 3 files changed, 28 insertions(+), 30 deletions(-) diff --git a/src/commands.rs b/src/commands.rs index f533999215..b7c19be716 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -97,31 +97,29 @@ pub(crate) fn delete_all_sessions(yes: bool, force: bool) { process::exit(0); } -pub(crate) fn kill_session(target_session: &Option) { - match target_session { - Some(target_session) => { - assert_session(target_session); - kill_session_impl(target_session); - process::exit(0); - }, - None => { - println!("Please specify the session name to kill."); - process::exit(1); - }, +pub(crate) fn kill_session(target_sessions: &[String]) { + if target_sessions.len() > 0 { + for session in target_sessions { + assert_session(session); + kill_session_impl(session); + } + process::exit(0); + } else { + println!("Please specify the session name to kill."); + process::exit(1); } } -pub(crate) fn delete_session(target_session: &Option, force: bool) { - match target_session { - Some(target_session) => { - assert_dead_session(target_session, force); - delete_session_impl(target_session, force); - process::exit(0); - }, - None => { - println!("Please specify the session name to delete."); - process::exit(1); - }, +pub(crate) fn delete_session(target_sessions: &[String], force: bool) { + if target_sessions.len() > 0 { + for session in target_sessions { + assert_dead_session(session, force); + delete_session_impl(session, force); + } + process::exit(0); + } else { + println!("Please specify the session name to delete."); + process::exit(1); } } diff --git a/src/main.rs b/src/main.rs index eacefc8a76..20f3de6bd0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -175,19 +175,19 @@ fn main() { commands::list_aliases(opts); } else if let Some(Command::Sessions(Sessions::KillAllSessions { yes })) = opts.command { commands::kill_all_sessions(yes); - } else if let Some(Command::Sessions(Sessions::KillSession { ref target_session })) = + } else if let Some(Command::Sessions(Sessions::KillSession { ref target_sessions })) = opts.command { - commands::kill_session(target_session); + commands::kill_session(target_sessions); } else if let Some(Command::Sessions(Sessions::DeleteAllSessions { yes, force })) = opts.command { commands::delete_all_sessions(yes, force); } else if let Some(Command::Sessions(Sessions::DeleteSession { - ref target_session, + ref target_sessions, force, })) = opts.command { - commands::delete_session(target_session, force); + commands::delete_session(target_sessions, force); } else if let Some(path) = opts.server { commands::start_server(path, opts.debug); } else { diff --git a/zellij-utils/src/cli.rs b/zellij-utils/src/cli.rs index f3c622dcbb..94a1774362 100644 --- a/zellij-utils/src/cli.rs +++ b/zellij-utils/src/cli.rs @@ -145,17 +145,17 @@ pub enum Sessions { /// Kill a specific session #[clap(visible_alias = "k")] KillSession { - /// Name of target session + /// Name of target session(s) to kill #[clap(value_parser)] - target_session: Option, + target_sessions: Vec, }, /// Delete a specific session #[clap(visible_alias = "d")] DeleteSession { - /// Name of target session + /// Name of target session(s) to kill #[clap(value_parser)] - target_session: Option, + target_sessions: Vec, /// Kill the session if it's running before deleting it #[clap(short, long, value_parser, takes_value(false), default_value("false"))] force: bool,