fix: panic on 'status -g name' with non-existant group name

This commit is contained in:
Arne Beer 2022-01-14 18:06:57 +01:00
parent 69fdf80d13
commit 4d8ce95bab
No known key found for this signature in database
GPG key ID: CC9408F679023B65
2 changed files with 14 additions and 5 deletions

View file

@ -47,6 +47,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Recover tasks from `Locked` state if editing fails [#267](https://github.com/Nukesor/pueue/issues/267)
- `pueue log` now behaves the same for local and remote logs.
Remote logs previously showed more lines under some circumstances.
- panic due to rogue `.unwrap()` when filtering for a non-existing group in `pueue status`.
## [1.0.5] - 2022-01-02

View file

@ -16,6 +16,7 @@ use crate::cli::SubCommand;
pub fn print_state(state: State, cli_command: &SubCommand, colors: &Colors, settings: &Settings) {
let (json, group_only) = match cli_command {
SubCommand::Status { json, group } => (*json, group.clone()),
SubCommand::FormatStatus { group } => (false, group.clone()),
_ => panic!("Got wrong Subcommand {cli_command:?} in print_state. This shouldn't happen!"),
};
@ -41,16 +42,23 @@ fn print_single_group(
settings: &Settings,
colors: &Colors,
mut sorted_tasks: BTreeMap<String, BTreeMap<usize, Task>>,
group: String,
group_name: String,
) {
let group = if let Some(group) = state.groups.get(&group_name) {
group
} else {
eprintln!("There exists no group \"{group_name}\"");
return;
};
// Only a single group is requested. Print that group and return.
let tasks = sorted_tasks.entry(group.clone()).or_default();
let headline = get_group_headline(&group, state.groups.get(&group).unwrap(), colors);
println!("{}", headline);
let tasks = sorted_tasks.entry(group_name.clone()).or_default();
let headline = get_group_headline(&group_name, group, colors);
println!("{headline}");
// Show a message if the requested group doesn't have any tasks.
if tasks.is_empty() {
println!("Task list is empty. Add tasks with `pueue add -g {group} -- [cmd]`");
println!("Task list is empty. Add tasks with `pueue add -g {group_name} -- [cmd]`");
return;
}
print_table(tasks, colors, settings);