session and seat management daemon
0

Configure Feed

Select the types of activity you want to include in your feed.

feat(cli): implement locking/unlocking all sessions

+47 -10
+47 -10
ctl/src/main.rs
··· 537 537 #[arg(value_name = "SESSION", help = "session id; omit with --current")] 538 538 ids: Vec<u32>, 539 539 }, 540 - #[command(about = "lock sessions")] 540 + #[command( 541 + about = "lock sessions", 542 + group(ArgGroup::new("target").args(["ids", "all"]).multiple(false)) 543 + )] 541 544 Lock { 545 + #[arg(long, help = "target all sessions")] 546 + all: bool, 542 547 #[arg(value_name = "SESSION", help = "session id; defaults to your session")] 543 548 ids: Vec<u32>, 544 549 }, 545 - #[command(about = "unlock sessions")] 550 + #[command( 551 + about = "unlock sessions", 552 + group(ArgGroup::new("target").args(["ids", "all"]).multiple(false)) 553 + )] 546 554 Unlock { 555 + #[arg(long, help = "target all sessions")] 556 + all: bool, 547 557 #[arg(value_name = "SESSION", help = "session id; defaults to your session")] 548 558 ids: Vec<u32>, 549 559 }, ··· 646 656 SessionCommand::List { .. } => None, 647 657 SessionCommand::Close { ids, .. } 648 658 | SessionCommand::Kill { ids, .. } 649 - | SessionCommand::Lock { ids } 650 - | SessionCommand::Unlock { ids } => Some(ids), 659 + | SessionCommand::Lock { ids, .. } 660 + | SessionCommand::Unlock { ids, .. } => Some(ids), 661 + } 662 + } 663 + 664 + const fn targets_all(command: &SessionCommand) -> bool { 665 + match command { 666 + SessionCommand::List { .. } 667 + | SessionCommand::Close { .. } 668 + | SessionCommand::Kill { .. } => false, 669 + SessionCommand::Lock { all, .. } | SessionCommand::Unlock { all, .. } => *all, 651 670 } 652 671 } 653 672 ··· 657 676 SessionCommand::Close { current, .. } | SessionCommand::Kill { current, .. } => { 658 677 *current 659 678 } 660 - SessionCommand::Lock { ids } | SessionCommand::Unlock { ids } => ids.is_empty(), 679 + SessionCommand::Lock { all, ids } | SessionCommand::Unlock { all, ids } => { 680 + !*all && ids.is_empty() 681 + } 661 682 } 662 683 } 663 684 ··· 989 1010 return Ok(()); 990 1011 } 991 1012 992 - let mut unmatched = Vec::new(); 1013 + let mut unmatched: Vec<&u32> = Vec::new(); 993 1014 let mut matched = Vec::new(); 994 1015 let mut denied = Vec::new(); 995 1016 996 - for id in ids { 997 - if let Some(session) = state.sessions.iter().find(|session| session.id == *id) { 1017 + if SessionAction::targets_all(&command) { 1018 + for session in &state.sessions { 998 1019 if session.can_modify { 999 1020 matched.push(session.object.clone()); 1000 1021 } else { 1001 1022 denied.push(session.id); 1002 1023 } 1003 - } else { 1004 - unmatched.push(id); 1024 + } 1025 + } else { 1026 + for id in ids { 1027 + if let Some(session) = 1028 + state.sessions.iter().find(|session| session.id == *id) 1029 + { 1030 + if session.can_modify { 1031 + matched.push(session.object.clone()); 1032 + } else { 1033 + denied.push(session.id); 1034 + } 1035 + } else { 1036 + unmatched.push(id); 1037 + } 1005 1038 } 1006 1039 } 1007 1040 ··· 1026 1059 "error:".red(), 1027 1060 action.name() 1028 1061 ); 1062 + return Ok(()); 1063 + } 1064 + 1065 + if matched.is_empty() { 1029 1066 return Ok(()); 1030 1067 } 1031 1068