fix: Only ask confirmation for tasks in resetting groups

This commit is contained in:
Arne Beer 2024-06-25 00:55:58 +02:00
parent 8316fcb4e2
commit 41a0daef1b
No known key found for this signature in database
GPG key ID: CC9408F679023B65

View file

@ -173,13 +173,23 @@ impl Client {
async fn handle_complex_command(&mut self) -> Result<bool> { async fn handle_complex_command(&mut self) -> Result<bool> {
// This match handles all "complex" commands. // This match handles all "complex" commands.
match &self.subcommand { match &self.subcommand {
SubCommand::Reset { force, .. } => { SubCommand::Reset { force, groups } => {
// Get the current state and check if there're any running tasks. // Get the current state and check if there're any running tasks.
// If there are, ask the user if they really want to reset the state. // If there are, ask the user if they really want to reset the state.
let state = get_state(&mut self.stream).await?; let state = get_state(&mut self.stream).await?;
// Get the groups that should be reset.
let groups: Vec<String> = if groups.is_empty() {
state.groups.keys().cloned().collect()
} else {
groups.clone()
};
// Check if there're any running tasks for that group
let running_tasks = state let running_tasks = state
.tasks .tasks
.iter() .iter()
.filter(|(_id, task)| groups.contains(&task.group))
.filter_map(|(id, task)| if task.is_running() { Some(*id) } else { None }) .filter_map(|(id, task)| if task.is_running() { Some(*id) } else { None })
.collect::<Vec<_>>(); .collect::<Vec<_>>();