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

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