From 97f546a69c52430d2b2748942a4fb7976eaefa89 Mon Sep 17 00:00:00 2001 From: Valerie Date: Mon, 1 Jul 2024 08:50:23 -0400 Subject: [PATCH] fixed 'add' command enforcing nest flag on detached sessions --- src/command/share.rs | 5 ++++- src/error.rs | 12 ++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/command/share.rs b/src/command/share.rs index 70019f5..2797c60 100644 --- a/src/command/share.rs +++ b/src/command/share.rs @@ -173,12 +173,15 @@ pub fn list() { pub fn new(state: &mut State) { util::terminal_enforce(); - state.nest_init(); // get optional flags let detached = state.flags.detached; let target_dir: Result = state.args.value_from_str(flag::TARGET); + // delayed nest_init; detached behavior conflicts with nest + if !detached { state.nest_init(); } + else if state.flags.nested { error::conflict_nest(Some("detached session is not nesting")); } + // get environment variables let window_name = env_var(env::NEW_WINDOW_NAME); diff --git a/src/error.rs b/src/error.rs index c792fe2..44ec43c 100644 --- a/src/error.rs +++ b/src/error.rs @@ -39,12 +39,20 @@ pub fn not_terminal() { /// tried to nest while not in a session; code 6 pub fn not_nesting() { - println!("remux: cannot use nesting flag outside a TMUX session"); + println!("remux: inappropriate nesting flag (-n); not in a session"); exit(6); } +/// operation requires nesting flag; code 6 pub fn prevent_nest() { - println!("remux: cannot nest sessions without the nest flag ('-n')"); + println!("remux: the nesting flag (-n) is required for nesting operation"); + exit(6); +} + +/// operation conflicts with nesting flag; code 6 +pub fn conflict_nest(reason: Option<&'static str>) { + if let Some(reason) = reason { println!("remux: inappropriate nesting flag (-n): {reason}"); } + else { println!("remux: nesting flag (-n) is inappropriate for this operation."); } exit(6); }