From cb026b3cfee3ea50448fa85564b98867cfc18722 Mon Sep 17 00:00:00 2001 From: Aram Drevekenin Date: Mon, 22 Apr 2024 12:42:37 +0200 Subject: [PATCH] fix(cli): merge attach options (#3288) --- zellij-utils/src/setup.rs | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/zellij-utils/src/setup.rs b/zellij-utils/src/setup.rs index d41465872..e41a20618 100644 --- a/zellij-utils/src/setup.rs +++ b/zellij-utils/src/setup.rs @@ -2,7 +2,7 @@ use crate::consts::ASSET_MAP; use crate::input::theme::Themes; use crate::{ - cli::{CliArgs, Command}, + cli::{CliArgs, Command, SessionCommand, Sessions}, consts::{ FEATURES, SYSTEM_DEFAULT_CONFIG_DIR, SYSTEM_DEFAULT_DATA_DIR_PREFIX, VERSION, ZELLIJ_DEFAULT_THEMES, ZELLIJ_PROJ_DIR, @@ -363,6 +363,11 @@ impl Setup { } else { None }; + + // the attach CLI command can also have its own Options, we need to merge them if they + // exist + let cli_config_options = merge_attach_command_options(cli_config_options, &cli_args); + let mut config_without_layout = config.clone(); let (layout, mut config) = Setup::parse_layout_and_override_config(cli_config_options.as_ref(), config, cli_args)?; @@ -683,6 +688,28 @@ impl Setup { } } +fn merge_attach_command_options( + cli_config_options: Option, + cli_args: &CliArgs, +) -> Option { + let cli_config_options = if let Some(Command::Sessions(Sessions::Attach { options, .. })) = + cli_args.command.clone() + { + match options.clone().as_deref() { + Some(SessionCommand::Options(options)) => match cli_config_options { + Some(cli_config_options) => { + Some(cli_config_options.merge_from_cli(options.to_owned().into())) + }, + None => Some(options.to_owned().into()), + }, + _ => cli_config_options, + } + } else { + cli_config_options + }; + cli_config_options +} + #[cfg(test)] mod setup_test { use super::Setup;