fixed 'add' command enforcing nest flag on detached sessions

This commit is contained in:
Valerie Wolfe 2024-07-01 08:50:23 -04:00
parent 44bad997cb
commit 97f546a69c
2 changed files with 14 additions and 3 deletions

View file

@ -173,12 +173,15 @@ pub fn list() {
pub fn new(state: &mut State) { pub fn new(state: &mut State) {
util::terminal_enforce(); util::terminal_enforce();
state.nest_init();
// get optional flags // get optional flags
let detached = state.flags.detached; let detached = state.flags.detached;
let target_dir: Result<String, Error> = state.args.value_from_str(flag::TARGET); let target_dir: Result<String, Error> = 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 // get environment variables
let window_name = env_var(env::NEW_WINDOW_NAME); let window_name = env_var(env::NEW_WINDOW_NAME);

View file

@ -39,12 +39,20 @@ pub fn not_terminal() {
/// tried to nest while not in a session; code 6 /// tried to nest while not in a session; code 6
pub fn not_nesting() { 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); exit(6);
} }
/// operation requires nesting flag; code 6
pub fn prevent_nest() { 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); exit(6);
} }