1use super::errors::{Result, err_definitions_not_found};
4use std::fs::{read_dir, read_to_string};
5
6pub fn load_definitions() -> Result<String> {
20 let mut files = vec![];
21 let paths = read_dir(".").expect("Failed to access current directory");
22 for entry in paths.flatten() {
23 let file_type = entry.file_type().expect("Failed to get file type");
24 if file_type.is_file() {
25 let file_name = entry.file_name().to_string_lossy().to_string();
26 if file_name.ends_with(".taskcmd") {
27 files.push(file_name);
28 }
29 }
30 }
31 files.sort();
32 files.reverse();
33 files.first().map_or_else(
34 || Err(err_definitions_not_found()),
35 |file_name| Ok(read_to_string(file_name).expect("Failed to read task definitions file")),
36 )
37}